setCompoundDrawables与setCompoundDrawablesWithIntrinsicBounds的区别

1 . 如果想手动设置大小的话就要用setCompoundDrawables,事先要给Drawable设置setBounds。

例子:
Resources res = TabTest.this.getResources();
Drawable myImage = res.getDrawable(R.drawable.home);
myImage.setBounds(1, 1, 100, 100);
button.setCompoundDrawables(null, myImage, null, null);

  1. 如果按照原有比例大小显示图片就使用setCompoundDrawablesWithIntrinsicBounds

例子:
button = (RadioButton) group.getChildAt(i);
Resources res = TabTest.this.getResources();
Drawable myImage = res.getDrawable(R.drawable.home);
button.setCompoundDrawablesWithIntrinsicBounds(null, myImage, null, null);

你可能感兴趣的:(setCompoundDrawables与setCompoundDrawablesWithIntrinsicBounds的区别)