Android display the problem of equal width picture

Source: Internet
Author: User

Android development often encountered a problem, that is, in the ListView, without knowing the picture width of the premise, another picture full screen (image width equal to the screen width, highly adaptive). In the ListView, just setting Scaletype,imageview.setbackground () is partly causing the picture to stretch distorted, and setimagedrawable () is not full screen. Refer to several programs on the Web, you summarize a relatively simple available:

ImageView layout:

1 <ImageView2         Android:id= "@+id/imgico"3 Android:layout_width= "Wrap_content"        4 Android:layout_height= "Wrap_content"5 Android:layout_marginleft= "15DP"6 Android:layout_marginright= "15DP"7 Android:layout_margintop= "10DP" 8 Android:adjustviewbounds= "true" 9 Android:scaletype= "Fitcenter"  Ten         />

Where Ajustviewbounds is to be set to True,fitcenter center alignment (if the width is set directly to Math_content also can be implemented, just if some pictures are long, will result in the ListView item layout is also very long)

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

1WindowManager WM =(WindowManager) Context.getsystemservice (context.window_service);2                 intScreenWidth =Wm.getdefaultdisplay (). getwidth ();3Viewgroup.layoutparams LP =holder.imgIco.getLayoutParams ();4Lp.width =ScreenWidth;5Lp.height =layoutparams.wrap_content;6 HOLDER.IMGICO.SETLAYOUTPARAMS (LP);7 holder.imgIco.setMaxWidth (screenwidth);8Holder.imgIco.setMaxHeight (ScreenWidth * 5);//it can actually be based on demand, and I'm testing 5 times times the maximum width here.

Android display the problem of equal width picture

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.