你好,游客 登录 注册 搜索
背景:
阅读新闻

GestureFlip -

[日期:2013-04-14] 来源:  作者: [字体: ]

翻页

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);
    }
}

 






收藏 推荐 打印 | 录入:admin | 阅读:
相关新闻