android - How to apply aspect ratio from material design specs on a view? -


i designing cardview app rich media header.

i try make this:

rich media header google material design specification

according google material design specification, picture should have 16:9 aspect ratio:

google rich media header specification

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

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -