2012-09-19 27 views
0

我在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> 

而且在佈局XML使用它:

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

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

</RelativeLayout> 

效果(第一個選項卡):

enter image description here

當單擊其他選項卡,我添加了繪製作爲他們的背景通過代碼:

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

但它顯示爲第一個不同:

enter image description here

如何解決呢?

回答

2

我相信當你在代碼中設置drawable時,填充被刪除。

我知道它不是你想聽到的,但這是一個android bug。有圍繞它的方法,但沒有乾淨。

看到這個問題: Where'd padding go, when setting background Drawable?

+0

我瘋了,用這些Android的bug。每天我都可以遇見一個:( – Freewind