android - How to apply aspect ratio from material design specs on a view? -
i designing cardview
app rich media header.
i try make this:
according google material design specification, picture should have 16:9 aspect ratio:
so, question, how achieve (code or xml) ?
if use defined size, not real 16:9 aspect ratio , have handle many resource files screen sizes , orientations.
else, did not succeed set size code because in onbindviewholder(...)
, getwidth()
on view return 0.
any idea ?
the easiest way use percentrelativelayout
parent viewgroup
. can set follow xml attributes on imageview
app:layout_widthpercent="100%" app:layout_aspectratio="178%"
another option write own custom imageview
, override onmeasure()
ensure view ends 16:9 ratio. this answer shows how that.
Comments
Post a Comment