Drawable的setBounds方法有四个参数,setBounds(int left, int top, int right, int bottom),这个四参数指的是drawable将在被绘制在canvas的哪个矩形区域内。
例如
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
上面的代码会将drawable绘制在canvas内部(100,100,500,500)表示的矩形区内(这个矩形区域的坐标是以canvas左上角为坐标原点的)
可以选择Drawable的最小尺寸,例如Drawable.setBounds(0,0,Drawable.getMinimumWidth(),Drawable.getMinimumHeight());
注意:一定要给Drawable设置bounds,不然无法显示。
由资源id获取Drawable对象的方法:
context.getResources().getDrawable(mineModelsInfo.imageResId);