此标签及其子代可以替换为一个和复合drawable

时间:2013-04-10 14:46:22

标签: android xml eclipse

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:orientation="horizontal"

 >

<ImageView

    android:id="@+id/file_icon"
    style="@style/fileChooserIcon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/desc" />

<TextView
    android:id="@+id/file_name"
    style="@style/fileChooserName"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
     />

错误:This tag and its children can be replaced by one <TextView/> and a compound drawable

我是android新手,并不完全了解错误是什么。某些溶液悲伤使其化合物,但没有得到它。

1 个答案:

答案 0 :(得分:6)

使用TextView的setCompoundDrawable*()方法或使用android:drawableLeft将TextView和ImageView合并为一个。

示例:

你来自

<LinearLayout 
android:layout_width="fill_parent"
android:layout_height="wrap_content" 
android:layout_marginTop="10dp"  
android:padding="5dp" >

<TextView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="My Compound Button" />

<ImageView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/my_drawable" />
</LinearLayout>

<TextView  
    android:layout_marginTop="10dp"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:text="My Compound Button" 
    android:drawableRight="@drawable/my_drawable"
    android:padding="5dp" />