Textview

Posted by ooftf on November 15, 2022

setCompoundDrawables 和 setCompoundDrawablesWithIntrinsicBounds 有什么区别

1
2
        Drawable leftIcon = ContextCompat.getDrawable(this, R.drawable.elder_right_icon);
        text.setCompoundDrawablesWithIntrinsicBounds(leftIcon,null,null,null);

使用setCompoundDrawablesWithIntrinsicBounds 最终显示大小是根据图片大小来的,通过 setBounds 修改大小是没有效果的

1
2
3
        Drawable leftIcon = ContextCompat.getDrawable(this, R.drawable.elder_right_icon);
        leftIcon.setBounds(0, 0, 200, 200);
        text.setCompoundDrawables(leftIcon,null,null,null);

使用 setCompoundDrawables 最终显示大小是根据 setBounds 的大小计算的,如果不设置 setBounds 显示大小为 0 即不显示