`
mickey_hou
  • 浏览: 239649 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Android触屏事件处理—1

阅读更多
1:程序在UI的界面中,显示当前的MotionEvent的动作和位置。
2:触摸屏主要通过实现以下函数来接收:
public boolean onTouchEvent(MotionEvent event)

/**
     * 初始化资源文件
     *
     * @param
     * @return void
     * @throws
     * @since TianTian
     */
    private void initResource()
    {
        touch_value1 = (TextView) findViewById(R.id.touch_value1);
       
        touch_value2 = (TextView) findViewById(R.id.touch_value2);
    }

/**
     * 触屏控制
     *
     * @param
     * @return void
     * @throws
     * @since TianTian
     */
    @Override
    public boolean onTouchEvent(MotionEvent event)
    {
        int Action = event.getAction(); //0 按下状态  1 抬起状态 2 拖动状态
        float X = event.getX();
        float Y = event.getY();
        touch_value1.setText("Action = "+ Action);
        touch_value2.setText("Postion = ("+X+","+Y+")");
        return true;
    }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics