Android development for single point of touch

Source: Internet
Author: User

A single touch is simple with respect to multi-touch.
To create a new project, first look at the layout file:

<relativelayout xmlns:android="Http://schemas.android.com/apk/res/android"xmlns:tools="Http://schemas.android.com/tools"Android:layout_width="Match_parent"android:layout_height="Match_parent"Android:paddingbottom="@dimen/activity_vertical_margin"android:paddingleft="@dimen/activity_horizontal_margin"android:paddingright="@dimen/activity_horizontal_margin"android:paddingtop="@dimen/activity_vertical_margin"tools:context="Com.example.touchevent.MainActivity"> <imageview android:id="@+id/iv"Android:layout_width="Match_parent"android:layout_height="Match_parent"Android:src="@drawable/jiafeimao"Android:scaletype="Matrix"/></relativelayout>

For a simple imageview, we will move this imageview in the activity:

 Public  class mainactivity extends Activity {    PrivateImageView IV;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_main); IV = (ImageView) This. Findviewbyid (R.ID.IV); Iv.setontouchlistener (NewOntouchlistener () {Private floatXPrivate floatY//model for manipulating pictures            PrivateMatrix Oldmatrix =NewMatrix ();PrivateMatrix Newmatrix =NewMatrix ();@Override             Public Boolean OnTouch(View V, motionevent event) {Switch(Event.getaction ()) {//Determine the type of Operation                 CaseMotionevent.action_down://Press to remember X, y coordinatesx = Event.getx ();                    y = event.gety (); Oldmatrix.set (Iv.getimagematrix ()); Break; CaseMotionevent.action_move://When moving                    //Use another model to remember where you pressedNewmatrix.set (Oldmatrix);//Mobile modelNewmatrix.settranslate (Event.getx ()-X, Event.gety ()-y); Break; }//Put the picture in the moving modelIv.setimagematrix (Newmatrix);return true;    }        }); }}

It's that simple.

Full code Download

Android development for single point of touch

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.