我的GridView未显示按下并聚焦选择器我的代码在下面。
myhomegrid.xml
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gwMenu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:columnWidth="90dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:drawSelectorOnTop="true"
android:listSelector="@layout/grid_selector"
/>
grid_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/pressedback" />
<item android:state_window_focused="false" android:drawable="@drawable/focusedback" />
<item android:state_window_focused="true" android:drawable="@drawable/focusedback" />
</selector>
menu.xml文件
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget44"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_x="201px"
android:layout_y="165px"
android:gravity="center_horizontal">
<ImageView
android:id="@+id/icon_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
<TextView
android:id="@+id/icon_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:gravity="center_horizontal"
android:textColor="#ffffff"
android:textColorHighlight="#656565">
</TextView>
</LinearLayout>
聚焦图像
按下图像
我想像下面的图像一样分离:
答案 0 :(得分:2)
您应该将grid_selector.xml放在drawable文件夹中,然后通过以下方式引用它:
android:listSelector="@drawable/grid_selector"
答案 1 :(得分:0)
您应该更正您的选择器,例如
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/pressedback" />
<item android:state_focused="true" android:drawable="@drawable/focusedback" />
<item android:state_selected="true" android:drawable="@drawable/focusedback" />
</selector>
UPD:我的不好,你不需要GridView的可点击和可聚焦的属性