zoukankan      html  css  js  c++  java
  • 【Android通过手势实现的缩放处理】

    android自定义手势缩放控件
    http://www.eoeandroid.com/thread-164077-1-1.html

    【eoeAndroid社区索引】图形图像之图像处理(缩放  旋转  转化)
    http://www.eoeandroid.com/thread-173242-1-1.html

    ---------------帖子正文----------------

    今天在http://www.eoeandroid.com/看到这个不错的技术点,拿出来分享一下,希望大家能够一起学习成长

    import android.app.Activity;
    import android.content.Context;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Paint;
    import android.os.Bundle;
    import android.util.DisplayMetrics;
    import android.view.MotionEvent;
    import android.view.View;
    
    /**
     * ...
     * 
     * @author vlinux
     * 
     */
    
    public class MultiTouchTestActivity extends Activity {
    
    /** Called when the activity is first created. */
    
    @Override
    
    public void onCreate(Bundle savedInstanceState) {
    
    super.onCreate(savedInstanceState);
    
    // setContentView(R.layout.main);
    
    View view = new MultiTouchView(this);
    
    setContentView(view);
    
    }
    
    class MultiTouchView extends View {
    
    private float x1;
    
    private float y1;
    
    private float x2;
    
    private float y2;
    
    public MultiTouchView(Context context) {
    
    super(context);
    
    // TODO Auto-generated constructor stub
    
    }
    
    @Override
    
    public boolean onTouchEvent(MotionEvent event) {
    
    // TODO Auto-generated method stub
    
    float size = event.getSize();
    
    int szi = (int) size;
    
    int dxi = szi >> 12;
    
    int dyit = ((1 << 12) - 1);
    
    int dyi = szi & dyit;
    
    DisplayMetrics metrics = getResources().getDisplayMetrics();
    
    float dx = metrics.widthPixels * dxi / (float) dyit;
    
    float dy = metrics.heightPixels * dyi / (float) dyit;
    
    x1 = event.getX();
    
    y1 = event.getY();
    
    x2 = x1 + dx;
    
    y2 = y1 + dy;
    
    invalidate();
    
    return true;
    
    }
    
    @Override
    
    protected void onDraw(Canvas canvas) {
    
    // TODO Auto-generated method stub
    
    super.onDraw(canvas);
     float r = (float) Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2)
    
    * (y1 - y2)) / 2;
    
    r = 50 >= r ? 50 : r;
    
    Paint paint = new Paint();
    
    paint.setColor(Color.BLUE);
    
    canvas.drawCircle(x1, y1, r, paint);
    
    }
  • 相关阅读:
    城市的划入划出效果
    文本溢出省略解决笔记css
    长串英文数字强制折行解决办法css
    Poj 2352 Star
    树状数组(Binary Indexed Trees,二分索引树)
    二叉树的层次遍历
    Uva 107 The Cat in the Hat
    Uva 10336 Rank the Languages
    Uva 536 Tree Recovery
    Uva10701 Pre, in and post
  • 原文地址:https://www.cnblogs.com/vus520/p/2851025.html
Copyright © 2011-2022 走看看