我们可以使用drawableLeft
或setCompundDrawables
为textview设置复合drawable,但是使用它只能将drawable放在left / right / top / bottom.But我想只放置drawables在Textview的左上角和右上角。
我怎样才能做到这一点 ?
答案 0 :(得分:3)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/imageView1"
android:text="@string/text" />
这样就可以了。
答案 1 :(得分:1)
我认为,有比3个视图更容易,更快捷的方式。您需要为图标准备适当的9patch,然后使用FrameLayout。甚至可以只使用与背景相同的单 EditText
/ TextView
。更多详细信息在this answer中进行了描述。