I use Actionbarsherlock and want to use my own action bar layout, but still want a navigation list. As a result, I turn on the IcsSpinner widget. However, the width is always large, as the largest element, and this is undesirable. I pulled it out of the action bar for debugging and got the same results:


Fragment Code
public class TestFragment extends SherlockFragment { private final String[] testStrings = {"Short","Not so long text"}; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view=inflater.inflate(R.layout.test_layout, container, false); IcsSpinner spinner = (IcsSpinner)view.findViewById(R.id.test_spinner); ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.spiner_test_row, R.id.spinner_text, testStrings); spinner.setAdapter(adapter); return(view); } }
test_layout.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <com.actionbarsherlock.internal.widget.IcsSpinner android:id="@+id/test_spinner" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout>
R.layout.spinner_test_row
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/spinner_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="16sp" />
Switching to the standard Spinner (on the gingerbread emulator) works fine:


Any suggestions?
source share