【问题标题】:Android custom spinnerAndroid 自定义微调器
【发布时间】:2012-02-22 08:45:13
【问题描述】:

我有一个自定义微调器,它使用两个自定义视图,一个用于下拉菜单,一个用于当前选定的项目。

我的问题是,当前选定项目的自定义视图始终至少与微调器列表中最长的项目一样宽,并且它在我的自定义视图左侧留下了相当大的间隙。如果我从微调器中选择最长的项目,差距就会消失。我已经为我的自定义视图尝试了 android:gravity="left" 。另请注意,这似乎只是 Android 3.0+ 的问题。

这是我的自定义微调器视图的代码:

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

【问题讨论】:

    标签: android android-layout spinner android-custom-view android-spinner


    【解决方案1】:

    这是故意的。它可以防止微调器随着选择的变化而急剧改变大小。

    您不应该在项目视图中包含箭头;这通常包含在微调器本身的背景 9 补丁中。微调器本身的重力设置控制微调器内选定项目视图的对齐方式。 Holo 主题将其对齐到左侧,而旧版主题水平居中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-13
      • 2014-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多