Custom screen-fit recipes

Source: Internet
Author: User

When doing a project, an app often needs a ' live ' display instead of a fixed width, such as when using the GridView to display pictures:

Of course, the number of columns is fixed, but what we need is that the aspect ratio of the picture will not become, the size of the picture is still to be done. So there is the following configuration

Assume that the aspect ratio of the picture is 16:9:

1Item_relatlayout =(relativelayout) Itemview.findviewbyid (r.id.item_relatlayout);2ImageView =(ImageView) Itemview.findviewbyid (R.id.imageview);3PLAYBTN =(TextView) Itemview.findviewbyid (r.id.play_tub);4Del_box =(CheckBox) Itemview.findviewbyid (r.id.del_ckbox);5             intPxwidth =Util.getscreanwith (context);6             intPxmargin = util.dp2px (context,0.1f);7Gridlayoutmanager.layoutparams Layoutparams =(Gridlayoutmanager.layoutparams) item_relatlayout.getlayoutparams ();8 Layoutparams.setmargins (pxmargin,pxmargin,pxmargin,pxmargin);9 Item_relatlayout.setlayoutparams (layoutparams);Ten             //total width minus values for all gaps One             intt = pxwidth-pxmargin*6; A             //re-calculate the width of the picture -Relativelayout.layoutparams params =(Relativelayout.layoutparams) imageview.getlayoutparams (); -Params.width = T/3; theParams.height = (int) ((T/3) * (0.5) ;//Calculate the aspect ratio -Imageview.setlayoutparams (params);

Only in this way, the size of the image will be changed with different screens, but the size ratio is still unchanged ...

Custom screen-fit recipes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.