Android 在GridView中使用图像选择器时膨胀类选择器时出错

Android 在GridView中使用图像选择器时膨胀类选择器时出错,android,gridview,selector,Android,Gridview,Selector,我使用了一个GridView和一个图像选择器,这样我的图像在按下和未按下时就不同了。所有东西都可以编译,但当我运行应用程序时,会出现一个错误“Binary XML file line#9:error Expling class selector” 是否可以在gridview中使用图像选择器?当我从xml中取出选择器时,它运行良好 以下是每个网格项的xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns

我使用了一个GridView和一个图像选择器,这样我的图像在按下和未按下时就不同了。所有东西都可以编译,但当我运行应用程序时,会出现一个错误“Binary XML file line#9:error Expling class selector”

是否可以在gridview中使用图像选择器?当我从xml中取出选择器时,它运行良好

以下是每个网格项的xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout    xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp" >
<selector   
     xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/status_button_down"
          android:state_pressed="true" />
    <item android:drawable="@drawable/status_button_down"
          android:state_focused="true" />
    <item android:drawable="@drawable/status_button_up" />
</selector>
<TextView
    android:id="@+id/grid_item_label"

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Status"    
        android:textSize="9pt"
        android:typeface="sans"
        android:textColor="#000000"  
        android:gravity="center_horizontal"
        android:layout_gravity="center_horizontal|bottom"

         />
</LinearLayout>

选择器实际上应该在“drawables”文件夹中设置为自己的.xml文件。然后你可以这样称呼它:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout    xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/my_selector" 
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp" >


谢谢,我这样做了,并在图片底部添加了一些额外的空间,效果很好。我还必须在文本的开头添加一些额外的空格,以便使其居中对齐,即使我指定了居中水平。如果你知道一个更好的方法,那么添加空格让我知道。你的文本视图宽度是“wrap_content”,这意味着居中它不会起任何作用,因为你的文本视图总是(基本上)与你的文本大小相同。您需要将其设置为“fill\u parent”或“match\u parent”(取决于api),以便让它执行您想要的操作。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout    xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/my_selector" 
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp" >