2015-05-15 47 views
2

它是一種聊天屏幕,Textview包含圖像(9-Patch Image)作爲背景可繪製。 所有設備的工作完美。 請參考圖片:Samsung Galaxy S3版本4.3中的Android佈局textview(保證金/填充)問題

All devices in Version 4.4 & version 5

其遇到的問題是,在採用Android 4.3三星S3中,圖像(9貼片)不能採取的TextView保證金或填充。背景圖片沒有得到保證。請參考圖片:

enter image description here

我已經嘗試了所有保證金,但它只是沒有在Android 4.3的體現。它是設備特定的還是Android 4.3的錯誤?

我該如何解決這個問題?

+0

是背景9patch?你可以把它添加到問題? – Lamorak

+0

@Lamorak - 是的,它是一個根據文本擴展的9補丁圖像。 –

+0

你能提供9個補丁映像嗎? – Lamorak

回答

0

當使用9-補丁圖像作爲背景時,您不必爲內部視圖設置邊距/填充。 9補丁的內容區域在右側和底部1像素條紋中定義。你的圖片有一個內容區域設置在它的全部,並導致在問題中所反映的行爲。

試試這個形象與正確設置的內容區域:

enter image description here

0

所以我的解決辦法是隻以編程方式設置填充,比如:

int leftRightPadding = ctx.getResources().getDimensionPixelSize(R.dimen.message_chat_padding_left_right); 
int bottomTopPadding = ctx.getResources().getDimensionPixelSize(R.dimen.message_chat_padding_bottom_top); 
text.setPadding(leftRightPadding, bottomTopPadding, leftRightPadding, bottomTopPadding);