Android Pictures move left and right

Source: Internet
Author: User

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

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.