日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ScaleGestureDetector使用注意事项

發布時間:2025/3/15 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ScaleGestureDetector使用注意事项 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

注:一定要通過view的onTouchEvent調用mScaleGestureDetector.onTouchEvent(ev);,只有這樣

才能調用回調函數:onScaleBegin

具體可以參加:android源碼:KenBurnsActivity.java

下面是轉載的文章:


Detects transformation gestures involving more than one pointer ("multitouch") using the supplied?MotionEvents.

?TheScaleGestureDetector.OnScaleGestureListener?callback will notify users when a particular gesture event has occurred. This class should only be used with?MotionEvents reported via touch. To use this class:
  • Create an instance of the?ScaleGestureDetector?for your?View
  • In the?(View's )onTouchEvent(MotionEvent)?method ensure you call?(ScaleGestureDetector's )onTouchEvent(MotionEvent). The methods defined in your callback will be executed when the events occur.
下面是測試的代碼:
  • public?class?TouchView?extends?View?{

  • ?private?Context?mContext;
  • ?private?Paint?mPaint;
  • ?private?Rect mRect;
  • ?private?ScaleGestureDetector mScaleGestureDetector;
  • ?
  • ?public?TouchView(Context?context)?{
  • ??super(context);
  • ??mContext?=?context;
  • ??mPaint?=?new?Paint();
  • ??mPaint.setColor(Color.BLUE);
  • ??mPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
  • ??mRect?=?new?Rect();
  • ??mRect.left?=?10;
  • ??mRect.top?=?10;
  • ??mRect.right?=?300;
  • ??mRect.bottom?=?400;
  • ??
  • ??mScaleGestureDetector?=?new?ScaleGestureDetector(context,?listener);
  • ?}
  • ?
  • ?OnScaleGestureListener listener?=?new?OnScaleGestureListener()?{
  • ??
  • ??public?void?onScaleEnd(ScaleGestureDetector?detector)?{
  • ???// TODO Auto-generated method stub
  • ???Log.i("OnScaleGestureListener",?"onScaleEnd");
  • ??}
  • ??
  • ??public?boolean?onScaleBegin(ScaleGestureDetector?detector)?{
  • ???// TODO Auto-generated method stub
  • ???Log.i("OnScaleGestureListener",?"onScaleBegin?detector.getCurrentSpan() = "?+?detector.getCurrentSpan());
  • ???detector.getCurrentSpan();
  • ???return?true;
  • ??}
  • ??
  • ??public?boolean?onScale(ScaleGestureDetector?detector)?{
  • ???// TODO Auto-generated method stub
  • ???float?cur?=?detector.getCurrentSpan();
  • ???float?pre?=?detector.getPreviousSpan();
  • ???float?cp?=?cur?-?pre;
  • ???Log.i("OnScaleGestureListener",?"onScale?detector.getCurrentSpan() = "?+?cur
  • ?????+?"?detector.getPreviousSpan() = "?+?pre?
  • ?????+?" cur - pre = "?+?(cur?-?pre));
  • ???if?(cp?<?-100?&&?!mScaled)?{
  • ????mScaled?=?true;
  • ????mRect.left?=?10+?50;
  • ????mRect.top?=?10?+?50;
  • ????mRect.right?=?300?-?50;
  • ????mRect.bottom?=?400?-?50;
  • ????invalidate();
  • ???}?else?if?(cp?>?100?&&?mScaled)?{
  • ????mScaled?=?false;
  • ????mRect.left?=?10;
  • ????mRect.top?=?10?;
  • ????mRect.right?=?300?;
  • ????mRect.bottom?=?400;
  • ????invalidate();
  • ???}
  • ???return?false;
  • ??}
  • ?};

  • ?boolean?mScaled?=?false;
  • ?/*@Override
  • ?protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  • ??int widthMode = MeasureSpec.getMode(widthMeasureSpec);
  • ??int width = MeasureSpec.getSize(widthMeasureSpec);
  • ??int heightMode = MeasureSpec.getMode(heightMeasureSpec);
  • ??int height = MeasureSpec.getSize(heightMeasureSpec);
  • ??super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  • ?}*/



  • ?@Override
  • ?protected?void?onDraw(Canvas?canvas)?{
  • ??canvas.drawRect(mRect,?mPaint);
  • ?}



  • ?@Override
  • ?public?boolean?onTouchEvent(MotionEvent?event)?{
  • ??System.out.println("event.getPointerCount() : "?+?event.getPointerCount());
  • ??mScaleGestureDetector.onTouchEvent(event);
  • ??return?true;
  • ?}
  • }
  • 轉載于:https://www.cnblogs.com/tanqiantot/archive/2012/10/12/3126845.html

    總結

    以上是生活随笔為你收集整理的ScaleGestureDetector使用注意事项的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。