Android ImageView width setting, highly adaptive

Source: Internet
Author: User

Recently encountered a demand, the requirement is not aware of the picture width and height of the case, let the picture in the specified width, while highly adaptive, in the network to find a bit, there are many solutions, and then for their own application, chose a modified smaller scheme, and finally proved that the effect is pretty good, recorded here, Hope to help people with the same needs.

First, you need to add android:adjustviewbounds= "true" to your ImageView layout

< ImageView             Android:id = "@+id/iv_custom_showdress_item_dress"             android:layout_width= "Fill_parent"            android:layout_height= "Wrap_ Content "            android:adjustviewbounds=" true "/>

Then, set the ImageView in the code. Maximum width and maximum height, because the Adjustviewbounds property only works if the maximum height and maximum width are set

WindowManager wm = (WindowManager) _context.getsystemservice (context.window_service);             int screenwidth = wm.getdefaultdisplay (). getwidth ();             = viewHolder.showDress.getLayoutParams ();             = screenwidth;             = layoutparams.wrap_content;            VIEWHOLDER.SHOWDRESS.SETLAYOUTPARAMS (LP);

Android ImageView width setting, highly adaptive

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.