前言
在Layout中指定好background和padding以後,程序裏面動態修改background之後padding就失效了,貌似是一個BUG,這裏找到了一篇英文文章,簡單翻譯分享一下。
正文
一、折中辦法
1.1方法一
int top = theView.getPaddingTop();
int right = theView.getPaddingRight();
int left = theView.getPaddingLeft();
theView.setBackgroundResource(R.drawable.entry_bg_with_image);
theView.setPadding(left, top, right, bottom);
1.2方法二
theView.setBackgroundResource(R.drawable.entry_bg_with_image);
theView.setPadding(pad, pad, pad, pad);
代碼說明:
實際上就是在setBackgroundResource之後重新設置一下padding。
二、原帖網址
轉自:http://www.cnblogs.com/over140/archive/2012/07/20/2600525.html