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主题将其与左侧对齐,而传统主题则横向居中。