0

我有一個自定義微調器,它使用兩個自定義視圖,一個用於下拉菜單,另一個用於當前選定的項目。Android自定義微調器

我的問題是,當前選定項目的自定義視圖始終至少與微調列表中最長的項目一樣寬,並且在我的自定義視圖的左側留下了相當大的間隙。如果我從微調器中選擇最長的項目,則間隙消失。我已經爲我的自定義視圖嘗試了android:gravity =「left」。另請注意,這似乎只是Android 3.0以上的問題。

This shows the gap when a short spinner entry is selected

Notice no gap is present between the icon and folder name

這裏是我的自定義視圖微調代碼:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/folder_detail" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="wrap_content"> 

<TextView android:text="Folder Name" 
    android:id="@+id/folder_name" android:textColor="#ffffff" 
    android:layout_width="wrap_content" android:textSize="16sp" 
    android:textStyle="bold" 
    android:layout_height="wrap_content" android:layout_marginTop="0dp"> 
</TextView> 

    <TextView android:id="@+id/folder_count" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="13sp" android:text="(0) " android:textColor="@color/light_blue" android:layout_marginLeft="2dp"/> 


<ImageView android:id="@+id/icon" android:src="@android:drawable/arrow_down_float" 
    android:layout_marginRight="1dp" android:scaleType="fitXY" 
    android:layout_gravity="bottom" android:layout_width="wrap_content" android:layout_height="wrap_content"/> 
</LinearLayout> 

回答

2

這是故意的。它可以防止微調者在選擇改變時大幅度改變大小。

你不打算在項目視圖中包含箭頭;這通常包含在Spinner本身的背景9補丁中。微調器上的重力設置控制着微調器內所選項目視圖的對齊。 Holo主題將其與左側對齊,而傳統主題則橫向居中。