2012-04-24 9 views
6

drawableの境界を取得したいが、getBoundsまたはcopyBoundsメソッドを使用すると、すべてRect(0、0 - 0、0)が返される。 このについてアンドロイドDrawable getBounds return 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)ですか?マーカーがnullでなく、私はtbar_single_pressed解像度を持っている....彼らは描かれていない限り

答えて

10

ドローアブルは寸法を持っていない

THX。あなたが渡しているイメージのサイズを取得したい場合は、drawable.getIntrinsicWidth()drawable.getIntrinsicHeight()

で独自の矩形を作成できます
関連する問題