This blog post, is on the basis of the previous revision, this time is to control the picture left and right move, moving up and down like it is not written
package com.yuanlp.testimage;import android.graphics.bitmap;import Android.graphics.bitmapfactory;import android.graphics.canvas;import android.graphics.color;import android.graphics.Matrix;import android.graphics.Paint;import android.os.Bundle;import android.support.v7.app.appcompatactivity;import android.view.view;import android.widget.imageview; Public class mainactivity extends appcompatactivity { private imageview iv; private int dx=0; //the distance from the left shift @Override protected void oncreate (bundle savedinstancestate) { super.oncreate (savedinstancestate); setcontentview (r.layout.activity_main2); iv = (ImageView) findviewbyid(R.ID.IV); } public void turnbig (View view) { bitmap bitmap = bitmapfactory.decoderesource ( Getresources (),  R.DRAWABLE.MEINV); matrix matrix=new matrix (); matrix.setscale (2,2), //magnification four times times, horizontal direction twice times, Twice times the vertical direction //buy a piece of paper Bitmap bitmap1 = bitmap.createbitmap (Bitmap.getwidth () * 2, bitmap.getheight () * 2, bitmap.getconfig ()) //buy an artboard canvas canvas = new canvas (BITMAP1); //Copy Session paint paint = new paint (); paint.setcolor (Color.Black); canvas.drawbitmap (bitmap,matrix,paint); //incoming new paper iv.setimagebitmap (BITMAP1); } public void turnsmall (View view) { bitmap bitmap = bitmapfactory.decoderesource (Getresources (),  R.DRAWABLE.MEINV); matrix matrix=new matrix (); matrix.setscale (0.5f,0.5f); //buy a paper bitmap bitmap1 = bitmap.createbitmap (Bitmap.getWidth ( ) / 2, bitmap.getheight () / 2, bitmap.getconfig ()); //buy an artboard canvas canvas=new canvas (BITMAP1); paint paint=new paint (); paint.setcolor (Color.Black); canvas.drawbitmap (Bitmap, Matrix,paint); iv.setimagebitmap (BITMAP1); } public void turnleft (View view) { bitmap bitmap = bitmapfactory.decoderesource (GetResources (), R.DRAWABLE.MEINV) dx--; //Each click, move left matrix matrix=new matrix (); matrix.settranslate (dx,0); //not moving in vertical direction, only left movement //Buy a paper &nbsP; bitmap bitmap1 = bitmap.createbitmap (Bitmap.getwidth (), bitmap.getHeight (), bitmap.getconfig ()) //buy an artboard canvas canvas=new canvas (BITMAP1); Paint paint=new paint (); canvas.drawcolor (Color.WHITE ); paint.setcolor (Color.Black); canvas.drawbitmap (Bitmap,matrix,paint); Iv.setimagebitmap (BITMAP1); } public void turnright ( View view) { bitmap bitmap = Bitmapfactory.decoderesource (Getresources (),  R.DRAWABLE.MEINV); dx++; //Each click, move to the left &Nbsp; matrix matrix=new matrix (); matrix.settranslate (dx,0); //not moving in vertical direction, only left movement //Buy a paper Bitmap bitmap1 = Bitmap.createbitmap (Bitmap.getwidth (), bitmap.getheight (), bitmap.getconfig ()); //buy an artboard canvas canvas=new canvas (BITMAP1); paint paint=new paint (); canvas.drawcolor (Color.White); paint.setcolor (Color.Black); canvas.drawbitmap ( Bitmap,matrix,paint); iv.setimagebitmap (BITMAP1); }}
This article is from the "Yuangushi" blog, make sure to keep this source http://cm0425.blog.51cto.com/10819451/1943890
Android Pictures move left and right