文章目录
1.解决方法2. 分析setBounds()方法2.1 使用1.解决方法
首先,解决这个问题方法见此处:
/weixin_36723200/article/details/53577015
简单来说,代码如下:
private void setRadioButtonPic(int rbtnId, int resourceId) {RadioButton rbtn = findViewById(rbtnId);//定义底部标签图片大小和位置(Context.getResources()更好用.)Drawable drawable_news = this.getResources().getDrawable(resourceId);//当这个图片被绘制时,给他绑定一个矩形 ltrb规定这个矩形drawable_news.setBounds(0, 0, 60, 60);//设置图片在文字的哪个方向rbtn.setCompoundDrawables(null, drawable_news, null, null);}
2. 分析setBounds()方法
/*** Specify a bounding rectangle for the Drawable. This is where the drawable* will draw when its draw() method is called.*/申明矩形边界。drawable将会在这个范围内画出来。就是把drawable缩放了。
public void setBounds(int left, int top, int right, int bottom)
-------(下图end就是bottom,不想改了)
2.1 使用
比如画布(Canvas):
......
canvas = new Canvas(bitmap);
drawable.setBounds(...);
drawable.draw(canvas);