what does android getIntrinsicHeight and getIntrinsicWidth mean?

前端 未结 3 399
旧巷少年郎
旧巷少年郎 2020-12-23 13:19

Hi I am confused by the two methods from Android Drawable class

getIntrinsicHeight()
getIntrinsicWidth()

api definition says http://develo

3条回答
  •  情歌与酒
    2020-12-23 13:45

    In android a drawable can be of many types such as color, bitmap, shape etc.

    Some of these drawables have an intrinsic height such as a BitmapDrawable which is the dimension of the image.

    Drawables such as ColorDrawable (used to draw just solid colors) don't have an intrinsic height. In this case the value of getIntrinsicHeight/Width returns -1.

    Even if a drawable doesn't have intrinsic height/width, every drawable needs to have their bounds set before they can render itself (i.e before you call mydrawable.draw(canvas))

    If you using a drawable as a background for a view, the view internally sets the bounds for you. But if you are using drawables in your own onDraw, then you need to explicitly set the bounds via setBounds.

提交回复
热议问题