Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关于android Drawable getBounds return Rect(0,0-0,0)_Android_Drawable - Fatal编程技术网

关于android Drawable getBounds return 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的边界,但是我使用getBounds或copyBounds方法。它们都返回Rect(0,0-0,0)。 代码是这样的

    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