Android: Cartoon app Development note in the ListView zoom in picture by screen width

Source: Internet
Author: User
Tags transparent color

First, the ListView

    <listview        android:id= "@+id/piclist"        android:layout_width= "fill_parent"        android:layout_height= " Wrap_content "        android:layout_above=" @+id/bottom "        android:layout_margintop=" 106DP "        android:divider= "#00000000"        android:listselector= "#00000000"        android:scrollbars= "None"/>

which
Android:divider= "#00000000"
Sets the interval color transparency for list items,
Android:listselector= "#00000000"
Set no background color when clicking a picture (transparent color without system background color)


Second, Piclist_item

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"      android:orientation= "vertical "    android:layout_width=" fill_parent "      android:layout_height=" fill_parent ">        <imageview         Android:id= "@+id/piclist_item"      android:layout_height= "wrap_content"   android:layout_width= "Fill_parent"         android:scaletype= "Fitstart"/></relativelayout>

Third, Piclistinfo

Package Com.cartoon.adapters;import Android.graphics.bitmap;public class Piclistinfo {private Bitmap picurl;   Image Address//below is the get and set method of the above attribute public Bitmap Getpicurl () {return picurl;} public void Setpicurl (Bitmap picurl) {picurl = Picurl;}}

Iv. Piclistadapter
Package Com.cartoon.adapters;import Java.util.arraylist;import Com.cartoon.r;import android.content.context;import Android.view.layoutinflater;import Android.view.view;import Android.view.view.measurespec;import Android.view.viewgroup;import Android.view.viewgroup.marginlayoutparams;import Android.view.WindowManager;import Android.widget.arrayadapter;import Android.widget.imageview;import Android.widget.listadapter;import Android.widget.listview;import Android.widget.relativelayout;import Android.widget.textview;public Class Piclistadapter extends Arrayadapter<piclistinfo>{public piclistadapter (context context, int Textviewresourceid , arraylist<piclistinfo> objects) {Super (context, Textviewresourceid, objects);} @Overridepublic view GetView (int position, view Convertview, ViewGroup parent) {Viewholder holder =null; View view;                WindowManager wm = (WindowManager) getcontext (). Getsystemservice (Context.window_service); int width = Wm.getdefaultdisplay (). GetWidth (); if (Convertview = = null) {view = Layoutinflater.from (GetContext ()). Inflate (R.layout.piclist_item, null); <pre NA Me= "Code" class= "Java" >//Set the size of the picture holder = new Viewholder (); Holder.piclist_item = (ImageView) View.findvie             Wbyid (R.id.piclist_item);       Viewgroup.layoutparams margin = new Viewgroup.layoutparams (Holder.piclist_item.getLayoutParams ());    relativelayout.layoutparams layoutparams  = new Relativelayout.layoutparams (margin);
Layoutparams.height = (int) (width*0.5677);//Set the height of the picture
Layoutparams.width = width; Set the width of a picture
Layoutparams.setmargins (15, 0, 15, 0);
Holder.piclist_item.setLayoutParams (Layoutparams);
Holder.piclist_item.setScaleType (ImageView.ScaleType.FIT_START); View.settag (holder);} else {view = Convertview;holder = (viewholder) Convertview.gettag ();} final Piclistinfo singleoder = GetItem (position); if (Singleoder! = null) {Holder.piclist_item.setImageBitmap (Singleoder.getpicurl ());} return view;} public class Viewholder{public ImageView Piclist_item;}}

Using Listview+adapter to encounter the height of a table item, a common method is to display the picture only in the narrow area to the left of each table item. And the project requires that the picture and screen width, height proportional scale, so first get the screen width

WindowManager wm = (WindowManager) getcontext ()                . Getsystemservice (context.window_service);                int width = Wm.getdefaultdisplay (). getwidth ();                int height = Wm.getdefaultdisplay (). GetHeight ();
Adjust the picture size again, the note has been written more clearly:

<pre name= "code" class= "java" >                Holder.piclist_item = (ImageView) View.findviewbyid (r.id.piclist_item);             Viewgroup.layoutparams margin9 = new Viewgroup.layoutparams (Holder.piclist_item.getLayoutParams ());       Relativelayout.layoutparams layoutparams = new Relativelayout.layoutparams (margin);
Layoutparams.height = (int) (width*0.5677);//Set the height of the picture
Layoutparams.width = width; Set the width of a picture
Layoutparams.setmargins (15, 0, 15, 0);//left and right margin 15.0px, consistent with the main frame
Holder.piclist_item.setLayoutParams (Layoutparams);
Holder.piclist_item.setScaleType (ImageView.ScaleType.FIT_START); Scale up or down to the width of the view, and then display it on top
View.settag (holder);

Because of the known picture aspect ratio, when you scale the width by the screen width, you simply multiply the height by the corresponding scale. or zoom through ScaleType.

Attached: ScaleType Properties

1) Center is   displayed by the original size of the image, when the picture is longer than the width of the view, the center portion of the captured picture is displayed 2) Center_crop   proportionally enlarges the size of the image to the center of the display, Make the picture's length and width equal to or greater than the width of the view 3) center_inside The   contents of the picture to the full center display, by proportionally reduced or the original size so that the picture length is equal to or less than the width of the View 4) Fit_center   Zoom in or out of the picture to the width of the view, and then Center 5) Fit_star the picture proportionally to the width of the view and then to the top   6) fit_end   enlarge or narrow the picture to the width of the view, Then at the bottom of the display 7) Fit_xy   does not scale the picture, the goal is to fill the entire picture with the entire view

If



Android: Cartoon app Development note in the ListView zoom in picture by screen width

Related Article

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.