写了这么一段代码:
<LinearLayout
android:orientation="horizontal"
android:layout_centerInParent="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<ImageView
android:id="@+id/grid_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/grid_text"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/app_name"/>
</LinearLayout>
eclipse提示:This tag and its children can be replaced by one <TextView/> and a compound drawable
最后发现原来可以直接给TextView加图片.. ,通过setCompoundDrawable 方法, 或者直接在xml中使用android:drawableLeft.、android:drawableRight等属性指定!

本文介绍了一种简化Android XML布局文件的方法,通过在TextView中使用复合图(compound drawable)来替代原有的LinearLayout和ImageView组合。这种方法不仅提高了布局效率,还增强了代码的可读性和维护性。
96

被折叠的 条评论
为什么被折叠?



