【发布时间】:2012-02-01 05:58:47
【问题描述】:
我已向我的 ListView 添加了自定义样式,但现在发生了一些奇怪的事情。
1)当我点击列表中的一个项目时,选择器(替代颜色)不会 出现。反而。标准的绿色选择器出现了,但它在后面 列表中每一行的圆角边缘。好像默认 带有标准黑色行的 ListView 在我的 styled
enter code here后面流血 一。有想法该怎么解决这个吗?有没有人遇到过 使用自定义 ListView 时出现类似问题?2)当我浏览列表时,背景颜色变回 标准黑色,不再是我设计的蓝色。
所以基本上这两个是我现在面临的问题,当我浏览列表时,选择器没有出现,黑色背景在我的灰色行后面“渗出”。 任何有关此问题的帮助/指导将不胜感激,谢谢!我附上了一张照片
这是我的 listview_row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dip"
android:background="@drawable/listview_background"
>
<ImageView
android:id="@+id/imgViewLogo"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_alignParentLeft="true"
android:scaleType="fitXY"
android:src="@drawable/imgview_drawable" >
</ImageView>
<TextView
android:id="@+id/txtViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_toRightOf="@+id/imgViewLogo"
android:text="TextView"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#43c6db"
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/txtViewDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/txtViewTitle"
android:layout_marginLeft="2dip"
android:layout_toRightOf="@+id/imgViewLogo"
android:textStyle="bold"
android:textColor="#000000"
android:text="TextView" >
</TextView>
</RelativeLayout>
这是我的主要 ListView 布局
<?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"
android:orientation="vertical"
android:background="#708090"
>
<ListView
android:id="@+id/lvAlbumList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:choiceMode="multipleChoice"
android:clickable="false"
android:divider="@drawable/list_divider"
android:dividerHeight="2dp"
android:padding="2dp"
android:listSelector="@drawable/selector"
android:cacheColorHint="#00000000"
>
</ListView>
</LinearLayout>
最后是我的 selector.xml,它是一个可绘制的状态列表
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/list_item_pressed"/>
<item android:state_focused="true"
android:drawable="@drawable/list_item_selected" />
<item android:drawable="@drawable/list_item_normal" />
</selector>
【问题讨论】:
-
你使用的是 xml 布局还是你让它动态化?
-
我是通过 XML 做的。我已将属性 listSelector=@drawable/custom_selector 添加到我的 ListView 标记中,但无济于事。
-
你能发布你的 Listview xml 代码吗?
-
也发布您的选择器 XML 文件,为您的第二个问题尝试将 listview cacheColorHint 设置为透明。
-
我选择@Frankenstein,他是对的 :)
标签: android listview coding-style listview-selector