Freewind
Freewind

Reputation: 198188

Add a drawable to a View, but the layout is incorrect

I defined a drawable in xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <padding
        android:bottom="1dp"
        android:left="0dp"
        android:right="0dp"
        android:top="5dp" />

    <corners
        android:bottomLeftRadius="0.1dp"
        android:bottomRightRadius="0.1dp"
        android:topLeftRadius="15dp"
        android:topRightRadius="15dp" />

</shape>

And use it in layout xml:

<RelativeLayout
    style="@style/TabHeader"
    android:background="@drawable/_moremsg_tab_back" >

    <TextView
        android:id="@+id/text"
        style="@style/TabText"
        android:text="TODO" />

</RelativeLayout>

The effect is (the first tab):

enter image description here

When click the other tabs, I add the drawable as their background by code:

v.setBackgroundDrawable(getResources().getDrawable(R.drawable._moremsg_tab_back));

But it displays different as the first one:

enter image description here

How to fix it?

Upvotes: 0

Views: 901

Answers (1)

Mark Hetherington
Mark Hetherington

Reputation: 1691

I believe padding is removed when you set a drawable in code.

I know its not what you want to hear but this is an android bug. There are ways around it, but nothing clean.

See this question: Where'd padding go, when setting background Drawable?

Upvotes: 2

Related Questions