3
votes

Is it possible to set drawableLeft outsite the TextViews 9patch background?

i'm using this code:

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/background_9patch"
        android:drawableLeft="@drawable/leftImg"
        android:text="Hello World" />

and I want that android:drawableLeft="@drawable/leftImg" will be at the left of the android:background="@drawable/background_9patch" .

  1. Can I do it with a single TextView or should i use TextView + ImageView in a LinearLayout ?
  2. Can I set the size of the drawable in: drawableLeft?
1

1 Answers

2
votes

Since your background is a custom 9-patch, you could just modify the background image to have a fixed-size transparent section on the left side of the stretchable content, which provides enough padding for the left Drawable. This is how the framework creates backgrounds for widgets like CheckBox that shift the text to be beside the corresponding button.