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>