我正在创建一个 Viewflipper。但是,当我跑步并尝试在屏幕上移动我的手时,什么也没有发生。我错过了什么?谢谢
这是java代码。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery);
flipper = (ViewFlipper)findViewById(R.id.flipperGallery);
flipper.setOnTouchListener((android.view.View.OnTouchListener) this);
}
@Override
public boolean onTouchEvent(MotionEvent touchevent) {
switch (touchevent.getAction())
{
case MotionEvent.ACTION_DOWN:
{
lastX = touchevent.getX();
Toast.makeText(this, "X: " + lastX, Toast.LENGTH_LONG).show();
break;
}
case MotionEvent.ACTION_UP:
{
float currentX = touchevent.getX();
if (lastX < currentX){
Toast.makeText(this, "scroll right: ", Toast.LENGTH_LONG).show();
if (flipper.getDisplayedChild()==0) break;
flipper.setInAnimation(this, R.anim.in_from_left);
flipper.setOutAnimation(this, R.anim.out_to_right);
flipper.showNext();
}
if (lastX > currentX){
Toast.makeText(this, "scroll left: ", Toast.LENGTH_LONG).show();
if (flipper.getDisplayedChild()==1) break;
flipper.setInAnimation(this, R.anim.in_from_right);
flipper.setOutAnimation(R.anim.out_to_left);
flipper.showPrevious();
}
break;
}
}
return false;
}
我正在创建一个 Viewflipper。但是,当我跑步并尝试在屏幕上移动我的手时,什么也没有发生。我错过了什么?谢谢