GestureFlip

翻页

public class MainActivity extends Activity implements OnGestureListener {
    private GestureDetector gd;
    private final int FLIP_DISTANCE = 50;
    private TextView tv1, tv2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        createView();
        gd = new GestureDetector(this);
    }

    protected void createView() {
        // TODO Auto-generated method stub
        tv1 = (TextView) findViewById(R.id.tv1);
        tv2 = (TextView) findViewById(R.id.tv2);
    }

    @Override
    public boolean onDown(MotionEvent arg0) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean onFling(MotionEvent arg0, MotionEvent arg1, float arg2,
            float arg3) {
        // TODO Auto-generated method stub
        if (Math.abs(arg0.getX() - arg1.getX()) > FLIP_DISTANCE) {
            if (tv1.getVisibility() == View.VISIBLE) {
                tv1.setVisibility(View.INVISIBLE);
                tv2.setVisibility(View.VISIBLE);
            } else {
                tv1.setVisibility(View.VISIBLE);
                tv2.setVisibility(View.INVISIBLE);
            }
        }
        return false;
    }

    @Override
    public void onLongPress(MotionEvent arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
            float arg3) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void onShowPress(MotionEvent arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean onSingleTapUp(MotionEvent arg0) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        // TODO Auto-generated method stub
        return gd.onTouchEvent(event);
    }
}

 

posted @ 2012-12-08 12:36  Mr.haox  阅读(239)  评论(0编辑  收藏  举报