Widget跟踪鼠标的代码块

public boolean onTouchEvent(MotionEvent event)
	{
		// TODO Auto-generated method stub
		x = (int) event.getX();
        y = (int) event.getY();
        tmp=(Button) findViewById(flag);
        AbsoluteLayout.LayoutParams params1=new AbsoluteLayout.LayoutParams(150,50,x-75,y-50);
        tmp.setLayoutParams(params1);
        switch(event.getAction())
        {   
            case MotionEvent.ACTION_DOWN:    
            	//tmp.invalidate();  
            	tmp.setText("选中down");
                break;   
            case MotionEvent.ACTION_UP:    
            	//tmp.invalidate();  
            	tmp.setText("选中UP");
                break;   
            case MotionEvent.ACTION_MOVE:   
            	//tmp.invalidate();   
            	tmp.setText("选中move");
                break; 
        }
        return super.onTouchEvent(event);
	}

你可能感兴趣的:(UP)