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