2011-01-31 79 views
9

我試圖創建像基於textview的控制吐司,我發現非常奇怪的行爲的情況下,當它有九個補丁drawable作爲背景。填補與九個補丁背景的圓形textview沒有視覺效果

這是XML定義:

<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" 
/> 

這是TextView的彩色背景: enter image description here

這是TextView的與繪製背景: enter image description here

據我所知,在ninepatch的情況下背景android使填充透明並僅將drawable用作文本的背景。但我想填補填補九區背景覆蓋區域。

是否有此問題的任何解決方案?

回答

26

嘗試任何這些:

  1. 設置通過「機器人:背景」背景ninepatch XML屬性,而不是編程;這與XML定義的填充進行合作。
  2. 如果您需要以編程方式設置背景,請嘗試在設置背景後重新設置填充(如果您設置了填充,然後設置背景,我會假定在九個補丁中定義的填充將覆蓋它)。
  3. 避免整個問題,只是設置你的ninepatch圖像本身的填補區域(這是正確的和底部有黑條)。
+1

感謝評析 - 1和2真的有幫助。 – 2011-02-01 11:48:35