美文网首页
setCompoundDrawables与setCompoun

setCompoundDrawables与setCompoun

作者: iBoss | 来源:发表于2017-07-17 15:58 被阅读0次

    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与setCompoun

          本文链接:https://www.haomeiwen.com/subject/svxqkxtx.html