Kirarahul
Kirarahul

Reputation: 13

This tag and its children can be replaced by one and a compound drawable

<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"
     />

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

i am new to android and don't exactly understand whats the error. certain solution sad to make it compound but didn't get it.

Upvotes: 0

Views: 3397

Answers (1)

Raghav Sood
Raghav Sood

Reputation: 82543

Merge the TextView and the ImageView into one, by using TextView's setCompoundDrawable*() methods, or using android:drawableLeft.

Example:

You go from

<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>

To

<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" />

Upvotes: 6

Related Questions