IT尋寶
          程序員的世界
          posts - 0,  comments - 2,  trackbacks - 0
          import android.app.Activity;
          02 import android.content.Context;
          03 import android.graphics.Canvas;
          04 import android.graphics.Color;
          05 import android.graphics.Paint;
          06 import android.os.Bundle;
          07 import android.util.DisplayMetrics;
          08 import android.view.MotionEvent;
          09 import android.view.View;
          10   
          11 /**
          12  * ...
          13  
          14  * @author vlinux
          15  
          16  */
          17 public class MultiTouchTestActivity extends Activity {
          18     /** Called when the activity is first created. */
          19     @Override
          20     public void onCreate(Bundle savedInstanceState) {
          21         super.onCreate(savedInstanceState);
          22         // setContentView(R.layout.main);
          23         View view = new MultiTouchView(this);
          24         setContentView(view);
          25     }
          26   
          27     class MultiTouchView extends View {
          28   
          29         private float x1;
          30         private float y1;
          31         private float x2;
          32         private float y2;
          33   
          34         public MultiTouchView(Context context) {
          35             super(context);
          36             // TODO Auto-generated constructor stub
          37         }
          38   
          39         @Override
          40         public boolean onTouchEvent(MotionEvent event) {
          41             // TODO Auto-generated method stub
          42   
          43             float size = event.getSize();
          44   
          45             int szi = (int) size;
          46             int dxi = szi >> 12;
          47             int dyit = ((1 << 12) - 1);
          48             int dyi = szi & dyit;
          49   
          50             DisplayMetrics metrics = getResources().getDisplayMetrics();
          51             float dx = metrics.widthPixels * dxi / (float) dyit;
          52             float dy = metrics.heightPixels * dyi / (float) dyit;
          53   
          54             x1 = event.getX();
          55             y1 = event.getY();
          56   
          57             x2 = x1 + dx;
          58             y2 = y1 + dy;
          59   
          60             invalidate();
          61   
          62             return true;
          63         }
          64   
          65         @Override
          66         protected void onDraw(Canvas canvas) {
          67             // TODO Auto-generated method stub
          68             super.onDraw(canvas);
          69   
          70             float r = (float) Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2)
          71                     * (y1 - y2)) / 2;
          72             r = 50 >= r ? 50 : r;
          73   
          74             Paint paint = new Paint();
          75             paint.setColor(Color.BLUE);
          76             canvas.drawCircle(x1, y1, r, paint);
          77   
          78         }
          79   
          80     }
          81   
          82 }
          posted on 2011-06-27 22:54 特務小強 閱讀(60) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          留言簿

          隨筆分類

          文章檔案

          搜索

          •  

          最新評論

          主站蜘蛛池模板: 长白| 于都县| 策勒县| 伊春市| 诸城市| 旬阳县| 盐边县| 昌图县| 松潘县| 嘉义县| 富锦市| 安福县| 龙南县| 介休市| 泊头市| 来安县| 德兴市| 宁化县| 洞头县| 扎鲁特旗| 兰西县| 玉田县| 平武县| 台山市| 辽阳市| 探索| 宜都市| 荣成市| 库尔勒市| 泸定县| 宁城县| 封开县| 盖州市| 安乡县| 出国| 宿州市| 耒阳市| 正宁县| 集安市| 新野县| 南川市|