2013-04-10 50 views
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" 
    /> 

錯誤:This tag and its children can be replaced by one <TextView/> and a compound drawable這個標籤及其子可以通過一個被替換的化合物和可繪製

我是新來的Android和不完全明白什麼錯誤。某些解決方案很難讓它複合,但沒有得到它。

+1

它不是一個錯誤......這是[皮棉(http://tools.android.com/tips/lint)提示 – Selvin 2013-04-10 14:51:08

+0

會影響項目嗎? – Kirarahul 2013-04-10 14:59:41

+0

聽聽這些提示會更好(檢查Raghav Sood的答案)......但是有時候我們可以忽略他們......在這個特殊的例子中,你可以得到性能提升(如果你使用提示),特別是當你使用這個佈局在ListView – Selvin 2013-04-10 15:04:45

回答

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

android:drawableLeft顯示錯誤 – Kirarahul 2013-04-10 14:59:14

+0

它顯示了什麼錯誤? – 2013-04-10 15:00:57

+0

有一個疑問:我應該改變整個代碼還是隻是textview和imageview? – Kirarahul 2013-04-10 15:04:41

相關問題