2012-10-05 49 views
4

我正在使用Actionbarsherlock並希望使用自定義的操作欄佈局,但仍需要導航列表。因此,我包含一個IcsSpinner小部件。然而,寬度總是和最大的物品一樣大,這是不希望的。我爆發出來的動作條調試,並仍然得到了相同的結果:Actionbarsherlock IcsSpinner - 寬度始終設置爲最寬項目

Short Text

enter image description here

片段代碼

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" /> 

更改爲標準的微調(上薑餅仿真器)正常工作:

enter image description here

enter image description here

有什麼建議?

+0

@JakeWharton Wharton你怎麼不使用內部並獲得com.actionbarsherlock.internal.widget.IcsSpinner上面的薑餅結果? – taraloca

回答

-1

這似乎是ActionBarSherlock中的IcsSpinner組件的默認行爲,即使在運行Honeycomb + Android版本時(例如, Square ICS設備上的方形錢包。

Jake建議不要使用IcsSpinner組件,但如果沒有它,則無法使用自定義操作欄佈局和維護導航列表UI。除非傑克能夠提出建議,否則我會繼續使用它,確保在他偉大的圖書館的未來版本上進行全面測試。

+0

那麼你是說沒有辦法將三角形微調器定位到selectedNavigationItem的寬度? – taraloca

+0

@taraloca正確,IcsSpinner始終和最長的物品一樣寬。你可以在傑克·沃頓自己寫的Square Wallet中看到這一點。 – nathanielwolf