Android setCompoundDrawablesWithIntrinsicBounds手工设置文本与图片相对位置说明
setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom)意思是设置Drawable显示在text的左、上、右、下位置(Textview、Button都以),作用效果和以下的xml布局中绿色背景那行代码一样,两个结合使用可以对图片进行变化
XML文件布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableTop="@drawable/t1" android:text="tete" /> </LinearLayout>
本文介绍如何在Android中使用setCompoundDrawablesWithIntrinsicBounds方法手工设置文本与图片的相对位置。通过具体示例展示了该方法如何实现类似XML布局文件中定义的图文混排效果。
1530

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



