突出显示ListView中的整个焦点行

时间:2011-09-05 10:07:32

标签: android listview

当行聚焦时,如何在列表视图中突出显示整行,而不是仅突出显示字符占用的空间。

例如下面,我希望突出显示整行,而不仅仅是“Hello Stackoverflow”。

|hello Stackoverflow.                                                    |END

2 个答案:

答案 0 :(得分:2)

在您添加的背景属性中的yor列表中 @绘制/ listItemDrawables

在名为listItemDrawables.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/onFocusImage" /> <!-- pressed -->
     <item android:drawable="@drawable/imageWithNoFocus" /> <!-- default -->
 </selector>

并在drawable文件夹中添加两个图像 onFocusImage.png 和 imageWithNoFocus

现在,当您从列表中选择某些内容时,您会看到所有内容都被选中

答案 1 :(得分:2)

确保您的商品layout_width设置为fill_parentlayout_height设置为wrap_content

相关问题