2013-12-09 50 views
-1

我對我的textview backgrnound使用android:tileMode =「repeat」。它是大約1px高度的圖像,但在重複變形左,右側.. 感謝您的幫助!Android背景圖像重複變形

屏幕:http://i.stack.imgur.com/yCXSQ.png

<?xml version="1.0" encoding="utf-8"?> 
<bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
    android:src="@drawable/chat_rep" 
    android:dither="true" 
    android:tileMode="repeat" /> 

回答

1

調用此函數與每個視圖具有背景:

public static void fixBackgroundRepeat(View view) { 
    Drawable bg = view.getBackground(); 
    if (bg != null) { 
     if (bg instanceof BitmapDrawable) { 
      BitmapDrawable bmp = (BitmapDrawable) bg; 
      bmp.mutate(); // make sure that we aren't sharing state anymore 
      bmp.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT); 
     } 
    } 
} 

這是張貼在這個問題的答案: "Tiled drawable sometimes stretches"

+0

TextView的消息查看=( TextView)v.findViewById(R.id.message_text); \t messageView.setText(message); \t fixBackgroundRepeat(messageView); 由於沒有變化.. http://2imgs.com/8866a78d5e

+0

其實,這看起來像是一個很好的機會讓你創建一個9補丁的背景圖片......你不應該做任何這在代碼中手動。 – Garett