This article describes the usage of the ZoomControls control using Android programming to implement image enlargement and zoom-out function. Share it for your reference, as follows:
MainActivity Code:
package ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; public class MainActivity extends Activity { private LinearLayout llLayout; private ZoomControls zoomcontrols; private ImageView img; private int id=0; private int displayWidth; private int displayHeight; private float scaleWidth = 1; private float scaleHeight = 1; private Bitmap bitmap; @Override public void onCreate(Bundle savedInstanceState) { (savedInstanceState); setContentView(.activity_main); llLayout =(LinearLayout)findViewById(); //Get the screen resolution DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); displayWidth = ; //Screen height minus the height of zoomControls displayHeight = ; bitmap = (getResources(), ); img =(ImageView)findViewById(); //();Hide zoomControls //(); Show zoomCONtrols zoomcontrols =(ZoomControls)findViewById(); img =(ImageView)findViewById(); (true); (true); //Picture enlargement (new OnClickListener() { public void onClick(View v) { int bmpWidth = (); int bmpHeight = (); //Set the picture enlargement but the proportion double scale = 1.25; //Calculate the proportion to enlarge this time scaleWidth =(float)(scaleWidth*scale); scaleHeight =(float)(scaleHeight*scale); //Generate new size but Bitmap object Matrix matrix = new Matrix(); (scaleWidth, scaleHeight); Bitmap resizeBmp = (bitmap,0,0,bmpWidth,bmpHeight,matrix,true); (resizeBmp); } }); //Picture reduction (new OnClickListener() { public void onClick(View v) { int bmpWidth = (); int bmpHeight = (); //Set the picture enlargement but the proportion double scale = 0.8; //Calculate the proportion to enlarge this time scaleWidth =(float)(scaleWidth*scale); scaleHeight =(float)(scaleHeight*scale); //Generate new size but Bitmap object Matrix matrix = new Matrix(); (scaleWidth, scaleHeight); Bitmap resizeBmp = (bitmap,0,0,bmpWidth,bmpHeight,matrix,true); (resizeBmp); } }); } }
activity_main layout file code:
<LinearLayout xmlns:andro android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android: > <ImageView android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/c" /> <ZoomControls android: android:layout_gravity="bottom" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
Common methods description:
hasFocus():Judge focus
hide():hide
onTouchEvent(MotionEvent event): This method is now used to handle touch screen mobile events
setIsZoomInEnabled(boolean isEnabled): Whether to allow enlargement
setIsZoomOutEnabled(boolean isEnabled): Whether to allow shrinkage
setOnZoomInClickListener( listener): Register an amplification monitor
setOnZoomOutClickListener( listener): Register a minified listener
setZoomSpeed(long speed): Set the zoom speed
show():show
For more information about Android related content, please check out the topic of this site:Summary of Android graphics and image processing skills》、《Android development introduction and advanced tutorial》、《Android debugging skills and solutions to common problems》、《Summary of the usage of basic Android components》、《Android View View Tips Summary》、《Android layout layout tips summary"and"Android control usage summary》
I hope this article will be helpful to everyone's Android programming design.