0

我正在尝试使用布局作为选择器,但是在膨胀视图时出现错误,并且应用程序在下面给出 ANR

org.xmlpull.v1.XmlPullParserException:二进制 XML 文件第 2 行:android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:877) 处的无效可绘制标签 LinearLayout

你有什么主意吗

谢谢

可绘制/selector_map_all.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
      <item android:drawable="@layout/map_atm_selected" android:state_selected="true" />
      <item android:drawable="@layout/map_atm" />
</selector>

布局/map_atm.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout    
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:aresource="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/List_color2"
    android:gravity="center"
    android:orientation="horizontal" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/ico_info" />

    <TextView
        style="@style/TextViewNormalOpac"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:text="Hepsi" />

</LinearLayout>

布局/map_atm_selected.xml

<? xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:aresource="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/List_color2"
    android:gravity="center"
    android:orientation="horizontal" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/ico_info" />

    <TextView
        style="@style/TextViewNormalOpac"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:text="Hepsi" />

</LinearLayout>
4

1 回答 1

1

您的异常的原因是因为您不能LinearLayout在选择器中使用,因为StateListDrawable类(实际上是选择器)只能作为状态保持可绘制对象,但LinearLayout不是可绘制对象。createFromXmlInner您可以在方法内或此处检查可用的 Drawables(除了普通图片)。

于 2013-07-30T11:41:48.847 回答