The Zoomcontrols control is a scalable control that enables two buttons to control the size of a picture

Source: Internet
Author: User

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "vertical"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"Android:id= "@+id/layout"    >    <ImageViewAndroid:id= "@+id/image"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:src= "@drawable/foot"        />    <ZoomcontrolsAndroid:id= "@+id/zoomcontrol"android:layout_gravity= "Bottom"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"        /></LinearLayout>
 Packagecom.example.yanlei.my;ImportAndroid.os.Bundle;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.os.Bundle;Importandroid.app.Activity;ImportAndroid.widget.Toast;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;Importandroid.app.Activity;ImportAndroid.graphics.Bitmap;Importandroid.graphics.BitmapFactory;ImportAndroid.graphics.Matrix;ImportAndroid.os.Bundle;ImportAndroid.util.DisplayMetrics;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.ImageView;Importandroid.widget.LinearLayout;ImportAndroid.widget.ZoomControls; Public classMainactivityextendsappcompatactivity {PrivateLinearLayout lllayout; PrivateZoomcontrols Zoomcontrols; PrivateImageView img; Private intID = 0; Private intDisplaywidth; Private intDisplayheight; Private floatScaleWidth = 1; Private floatScaleHeight = 1; PrivateBitmap Bitmap; @Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); Lllayout=(LinearLayout) Findviewbyid (r.id.layout); //Get screen resolution sizeDisplaymetrics DM =NewDisplaymetrics ();        Getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM); Displaywidth=Dm.widthpixels; //screen height minus the height of zoomcontrolsDisplayheight =Dm.heightpixels; Bitmap=Bitmapfactory.decoderesource (Getresources (), r.drawable.foot); IMG=(ImageView) Findviewbyid (r.id.image); //zoom.hide (); Hide Zoomcontrols//zoom.show (); Show ZoomcontrolsZoomcontrols=(Zoomcontrols) Findviewbyid (R.id.zoomcontrol); IMG=(ImageView) Findviewbyid (r.id.image); Zoomcontrols.setiszoominenabled (true); Zoomcontrols.setiszoomoutenabled (true); //image magnificationZoomcontrols.setonzoominclicklistener (NewOnclicklistener () { Public voidOnClick (View v) {intBmpwidth =bitmap.getwidth (); intBmpheight =bitmap.getheight (); //set picture to enlarge but scale                DoubleScale = 1.25; //calculate the ratio to enlarge this time.ScaleWidth = (float) (ScaleWidth *Scale ); ScaleHeight= (float) (ScaleHeight *Scale ); //produces a new size but bitmap objectMatrix Matrix =NewMatrix ();                Matrix.postscale (ScaleWidth, ScaleHeight); Bitmap resizebmp= Bitmap.createbitmap (Bitmap, 0, 0, bmpwidth, bmpheight, Matrix,true);            Img.setimagebitmap (resizebmp);        }        }); //Picture ReductionZoomcontrols.setonzoomoutclicklistener (NewOnclicklistener () { Public voidOnClick (View v) {intBmpwidth =bitmap.getwidth (); intBmpheight =bitmap.getheight (); //set picture to enlarge but scale                DoubleScale = 0.8; //calculate the ratio to enlarge this time.ScaleWidth = (float) (ScaleWidth *Scale ); ScaleHeight= (float) (ScaleHeight *Scale ); //produces a new size but bitmap objectMatrix Matrix =NewMatrix ();                Matrix.postscale (ScaleWidth, ScaleHeight); Bitmap resizebmp= Bitmap.createbitmap (Bitmap, 0, 0, bmpwidth, bmpheight, Matrix,true);            Img.setimagebitmap (resizebmp);    }        }); }}

Reference: http://blog.csdn.net/jianghuiquan/article/details/8350538

The Zoomcontrols control is a scalable control that enables two buttons to control the size of a 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.