在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > Android應(yīng)用開發(fā) ScaleGestureDetector(縮放手勢

            Android應(yīng)用開發(fā) ScaleGestureDetector(縮放手勢

            作者: 時間:2016-09-12 來源:網(wǎng)絡(luò) 收藏

            一、概述

            本文引用地址:http://www.biyoush.com/article/201609/305037.htm

            ScaleGestureDetector這個類是專門用來檢測兩個手指在屏幕上做縮放的手勢用的,最簡單的應(yīng)用就是用來縮放圖片或者縮放網(wǎng)頁。

            二、要求

            利用ScaleGestureDetector這個類實現(xiàn)圖片縮放。

            三、實現(xiàn)

            新建工程MyScale,修改main.xml文件,在里面添加一個Button和一個SurfaceView,如下:

            android:layout_width=fill_parent

            android:layout_height=fill_parent

            android:orientation=vertical >

            android:id=@+id/button

            android:layout_width=fill_parent

            android:layout_height=wrap_content

            android:text=顯示圖片

            />

            android:id=@+id/surfaceview

            android:layout_width=fill_parent

            android:layout_height=fill_parent

            />

            修改MyScaleActivity.java文件,主要是實現(xiàn)按鈕的監(jiān)聽和定義一個類實現(xiàn)ScaleGestureDetector.OnScaleGestureListener接口:

            package com.nan.scale;

            import android.app.Activity;

            import android.graphics.Bitmap;

            import android.graphics.BitmapFactory;

            import android.graphics.Canvas;

            import android.graphics.Color;

            import android.graphics.Matrix;

            import android.graphics.Rect;

            import android.os.Bundle;

            import android.view.MotionEvent;

            import android.view.ScaleGestureDetector;

            import android.view.SurfaceHolder;

            import android.view.SurfaceView;

            import android.view.View;

            import android.widget.Button;

            public class MyScaleActivity extends Activity

            {

            private Button mButton = null;

            private SurfaceView mSurfaceView = null;

            private SurfaceHolder mSurfaceHolder = null;

            private ScaleGestureDetector mScaleGestureDetector = null;

            private Bitmap mBitmap = null;

            @Override

            public void onCreate(Bundle savedInstanceState)

            {

            super.onCreate(savedInstanceState);

            setContentView(R.layout.main);

            mSurfaceView = (SurfaceView)this.findViewById(R.id.surfaceview);

            mSurfaceHolder = mSurfaceView.getHolder();

            mScaleGestureDetector = new ScaleGestureDetector(this,new ScaleGestureListener());

            mButton = (Button)this.findViewById(R.id.button);

            //按鈕監(jiān)聽

            mButton.setOnClickListener(new View.OnClickListener()

            {

            @Override

            public void onClick(View v)

            {

            // TODO Auto-generated method stub

            mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.mmm);

            //鎖定整個SurfaceView

            Canvas mCanvas = mSurfaceHolder.lockCanvas();

            //畫圖

            mCanvas.drawBitmap(mBitmap, 0f, 0f, null);

            //繪制完成,提交修改

            mSurfaceHolder.unlockCanvasAndPost(mCanvas);

            //重新鎖一次

            mSurfaceHolder.lockCanvas(new Rect(0, 0, 0, 0));

            mSurfaceHolder.unlockCanvasAndPost(mCanvas);

            }

            });

            }

            @Override

            public boolean onTouchEvent(MotionEvent event)

            {

            //返回給ScaleGestureDetector來處理

            return mScaleGestureDetector.onTouchEvent(event);

            }

            public class ScaleGestureListener implements ScaleGestureDetector.OnScaleGestureListener

            {

            @Override

            public boolean onScale(ScaleGestureDetector detector)

            {

            // TODO Auto-generated method stub

            Matrix mMatrix = new Matrix();

            //縮放比例

            float scale = detector.getScaleFactor()/3;

            mMatrix.setScale(scale, scale);

            //鎖定整個SurfaceView

            Canvas mCanvas = mSurfaceHolder.lockCanvas();

            //清屏

            mCanvas.drawColor(Color.BLACK);

            //畫縮放后的圖

            mCanvas.drawBitmap(mBitmap, mMatrix, null);

            //繪制完成,提交修改

            mSurfaceHolder.unlockCanvasAndPost(mCanvas);

            //重新鎖一次

            mSurfaceHolder.lockCanvas(new Rect(0, 0, 0, 0));

            mSurfaceHolder.unlockCanvasAndPost(mCanvas);

            return false;

            }

            @Override

            public boolean onScaleBegin(ScaleGestureDetector detector)

            {

            // TODO Auto-generated method stub

            //一定要返回true才會進入onScale()這個函數(shù)

            return true;

            }

            @Override

            public void onScaleEnd(ScaleGestureDetector detector)

            {

            // TODO Auto-generated method stub

            }

            }

            }



            關(guān)鍵詞:

            評論


            相關(guān)推薦

            技術(shù)專區(qū)

            關(guān)閉