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

codeMagic
  • 44,549
  • 13
  • 77
  • 93
Kirarahul
  • 13
  • 1
  • 3
  • 1
    it's not an error ... it's [lint](http://tools.android.com/tips/lint) hint – Selvin Apr 10 '13 at 14:51
  • will it affect the project? – Kirarahul Apr 10 '13 at 14:59
  • it is better for us to listen those hints (check Raghav Sood's answer) ... but sometimes we can ignore 'em ... in this particular example you can get performance boost(if you use the hint) especially if you are using this layout in ListView – Selvin Apr 10 '13 at 15:04
  • why downvote? this is a valid question – yano May 22 '14 at 18:27
  • possible duplicate of [android layout: This tag and its children can be replaced by one and a compound drawable](http://stackoverflow.com/questions/3214424/android-layout-this-tag-and-its-children-can-be-replaced-by-one-textview-and) – Pooja May 06 '15 at 10:51

1 Answers1

6

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" />
Raghav Sood
  • 81,899
  • 22
  • 187
  • 195