关于android Drawable getBounds return Rect(0,0-0,0)
我想要得到drawable的边界,但是我使用getBounds或copyBounds方法。它们都返回Rect(0,0-0,0)。 代码是这样的关于android Drawable getBounds return Rect(0,0-0,0),android,drawable,Android,Drawable,我想要得到drawable的边界,但是我使用getBounds或copyBounds方法。它们都返回Rect(0,0-0,0)。 代码是这样的 Drawable marker = getResources().getDrawable( R.drawable.tbar_single_pressed); Rect copyRect = marker.copyBounds(); Rect getRect= marker.getBounds(); 那么结
Drawable marker = getResources().getDrawable(
R.drawable.tbar_single_pressed);
Rect copyRect = marker.copyBounds();
Rect getRect= marker.getBounds();
那么结果呢
copyRect是Rect(0,0-0,0)
getRect也是Rect(0,0-0,0)
为什么??标记不是空的,我按下了res tbar_single_
thx可绘制的对象没有尺寸,除非已绘制。如果您想获得要传递的图像的大小,可以使用
drawable.getIntrinsicWidth()
和drawable.getIntrinsicHeight()创建自己的rect