We can set compound drawables for textview as below using drawableLeft
or setCompundDrawables
but using this its only possible to place the drawable on left / right / top / bottom.But i want to put drawables only at top-left and top-right of the Textview.
How can i do that ?
<?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" />
This would do it.
I think, there's an easier and faster way than have 3 views. You need to prepare proper 9patch for icon and then use FrameLayout. It's even possible to have only single EditText
/ TextView
using the same drawable as their background. More details are described in this answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With