1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Android drawable.setBounds()+设置RadioButton的图片大小和位置

Android drawable.setBounds()+设置RadioButton的图片大小和位置

时间:2020-10-11 17:35:10

相关推荐

Android drawable.setBounds()+设置RadioButton的图片大小和位置

文章目录

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);

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。