Erez
Erez

Reputation: 2655

Android: Is It Possible To Set drawableLeft Outsite The TextViews 9patch Background?

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?

Upvotes: 3

Views: 441

Answers (1)

devunwired
devunwired

Reputation: 63303

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.

Upvotes: 2

Related Questions