【发布时间】:2012-02-01 00:50:11
【问题描述】:
我目前正在开发一个 Android 平板电脑应用程序,它有两个片段,一个列表片段和一个详细信息片段。
我正在尝试让我的名单类似于人员和电子邮件,其中在选择项目背景的情况下更改,三角形位于列表的右侧。
我目前在设置列表中所选项目的背景时遇到困难。 正如我在列表视图中所了解的那样,我应该将 android:listSelector 设置为可绘制对象,并且一切都应该工作。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="8dp"
>
<ListView android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:listSelector="@drawable/selected_background"
/>
<TextView android:id="@id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="No data. Please check your internet connection." android:gravity="center"/>
</LinearLayout>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/hukd_orange_faded" />
</shape>
当我这样做时,彩色项目的背景不会改变,直到我开始滚动列表。不仅如此,背景还会闪烁并经常回到标准背景颜色。
我在网上查了一下,似乎 Holo.light 有问题,如下所示Android list selector gets stuck when using Theme.Light 两种状态都试过了,问题依然存在。
【问题讨论】:
-
selected_background drawable 引用了底部的形状。
标签: android listview android-layout android-3.0-honeycomb android-4.0-ice-cream-sandwich