Android TextView Button setPadding不起作用

来源:互联网 发布:美团外卖消费数据分析 编辑:程序博客网 时间:2024/06/04 23:39

代码说明: setBackgroundResource之后重新设置一下padding

一、折中办法

1.1 方法一

    int bottom = theView.getPaddingBottom();
    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 方法二 

  int pad = resources.getDimensionPixelSize(R.dimen.linear_layout_padding);
  theView.setBackgroundResource(R.drawable.entry_bg_with_image);
  theView.setPadding(pad, pad, pad, pad);

 

二、原帖网址

http://stackoverflow.com/questions/5890379/android-setbackgroundresource-discards-my-xml-layout-attributes

 

三、搜索关键字

GOOGLE:"android setbackgroundresource changes padding


转自:http://www.cnblogs.com/over140/archive/2012/07/20/2600525.html

0 0