单击Android GridView不会突出显示

时间:2014-07-31 15:07:29

标签: android android-listview android-gridview

当我点击下方图片上的GridView项目时,它的项目不会突出显示。

我如何解决这个问题?

enter image description here

我试过这个:

<GridView
    android:id="@+id/GridView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_weight="1"
    android:cacheColorHint="@android:color/transparent"
    android:fadingEdge="none"
    android:horizontalSpacing="1dp"
    android:listSelector="@drawable/touch_listener"
    android:numColumns="2"
    android:scrollbars="none"
    android:background="#000"
    android:verticalSpacing="2dp" />

<item android:state_focused="true" android:state_pressed="true"><color android:color="#99a8c038" />
</item>
<item android:state_focused="false" android:state_pressed="true"><color android:color="#99a8c038" />
</item>
<item android:state_focused="true"><color android:color="#99a8c038" />
</item>
<item android:state_focused="false" android:state_pressed="false"><color android:color="#00a8c038" />
</item>

1 个答案:

答案 0 :(得分:0)

一个选项必须是使用&#34;选择器&#34;

<GridView
...
...
android:listSelector="@drawable/my_grid__selector"
...
...>
</GridView>

res/drawable文件夹中创建my_grid__selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/yellow" android:state_selected="true"/>
    <item android:drawable="@color/transparent"/>    
</selector>

一定要添加proeperty

android:focusableInTouchMode="true"