Padding arround textview with nine patch background have no visual effect

Alexey Kruchenok picture Alexey Kruchenok · Jan 31, 2011 · Viewed 8.4k times · Source

Im trying to create toast like control based on textview, and i found very strange behavior of textview in case when it have nine patch drawable as background.

This is xml definition:

<by.pplware.view.QuickInfo
    android:id="@+id/quickinfo"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:padding="20px"
    android:textSize="20px"
    android:textStyle="bold"
    android:typeface="serif"
    android:background="#FFFF0000"
/>

this is textview with color background: enter image description here

this is textview with drawable background : enter image description here

As i understand, in case of ninepatch background android make padding transparent and use drawable only as background for text. But I want to include padding into area covered with ninepatch background.

Is there any solution for this issue ?

Answer

Yoni Samlan picture Yoni Samlan · Jan 31, 2011

Try any of these:

  1. Set the background ninepatch via the "android:background" xml property instead of programatically; this cooperates with XML-defined padding.
  2. If you need to set the background programatically, try to re-set the padding after setting the background (if you set the padding then set the background, I'd assume the padding defined in the ninepatch itself overrides it).
  3. Avoid the entire issue and just set the padding areas in your ninepatch image itself (that's the right and bottom black bars).