android - Overriding ImageView minHeight dynamically -
i have imageview populated url. when image comes in scale using "centerinside" policy, nice , adjust imageview bounds using "adjustviewbounds".
before download image don't know would-be size of imageview. however, need display placeholder of reasonable size. put in "minheight=150dp" color background.
<imageview android:id="@+id/leadimageview" android:layout_width="match_parent" android:layout_height="wrap_content" android:minheight="150dp" android:background="@color/color_primary" android:adjustviewbounds="true" android:scaletype="centerinside" />
now, has consequence if downloaded image smaller 150 dp imageview still occupy 150dp, don't want.
so have tried build derived imageview class overrides minheight if drawable present, this:
class someimageview extends imageview { protected int getsuggestedminimumheight() { if (getdrawable() != null) return 0; return super.getsuggestedminimumheight(); } }
i did in different variations, seems getdrawable() null when in place in imagevew. without diving internal machinery of imageview hard guess why it's so.
maybe suggest approach or workaround override minheight 0 when drawable set on imageview.
you should able alter minheight attribute programmatically within code, once know actual image dimensions. imageview inherits method setminimumheight(int)
view class.
Comments
Post a Comment