2024年3月9日发(作者:)
Android的实现左右滚动效果
public class TestFlip extends Activity implements OnGestureListener {
private ViewFlipper flipper;
private GestureDetector detector;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
te(savedInstanceState);
setContentView();
detector = new GestureDetector(this);
flipper = (ViewFlipper) ewById(ipper01);
w(addView(1));
w(addView(2));
w(addView(3));
w(addView(4));
}
private View addView(int layout) {
LayoutInflater inflater = (LayoutInflater) getSystemService(_INFLATER_SERVICE);
View view = e(layout, null);
return view;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return hEvent(event);
}
@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if (() - () > 120) {
nimation(imation(this, _left_in));
Animation(imation(this, _left_out));
xt();
return true;
} else if (() - () < -120) {
nimation(imation(this, _right_in));
Animation(imation(this, _right_out));
evious();
return true;
}
return false;
}
@Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
}


发布评论