android的setBackgroundResource()出現padding失效的問題

android的

checkLine.setBackgroundResource(R.drawable.bg_rectangle);

設置背景後出現padding失效的問題

方式一  先獲取checkLine的padding值 在setBackgroundResource()之後增加 setPadding 代碼

int left = checkLine.getPaddingLeft();
int right = checkLine.getPaddingRight();
int top = checkLine.getPaddingTop();
int bottom = checkLine.getPaddingBottom();
 

checkLine.setBackgroundResource(R.drawable.bg_rectangle);
checkLine.setPadding(int left, int top, int right, int bottom)

方拾二 : 在子View中加margin控制內容和邊界 的間距,親測可行,記錄下

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章