android之滑屏
<LineLayout>
<ViewFlipper android:id="@+id/ViewFlipper"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:text="第 1 页"
android:textSize="35dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="115dp"
android:layout_y="20dp"/>
</AbsoluteLayout>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:text="第 2 页"
android:textSize="35dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="120dp"
android:layout_y="20dp"/>
</AbsoluteLayout>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:text="第 3 页"
android:textSize="35dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="120dp"
android:layout_y="20dp"/>
</AbsoluteLayout>
</ViewFlipper>
</LineLayout>
public class MainActivity extends Activity implements OnGestureListener {
private ViewFlipper flipper;
private GestureDetector detector;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
detector = new GestureDetector(this);
flipper = (ViewFlipper) this.findViewById(R.id.ViewFlipper);
}
public boolean onDoubleTap(MotionEvent e) {
if(flipper.isFlipping()) {
flipper.stopFlipping();
}else {
flipper.startFlipping();
}
return true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return this.detector.onTouchEvent(event);
}
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY) {
if (e1.getX() - e2.getX() > 60) {
this.flipper.showNext();
return true;
} else if (e1.getX() - e2.getX() < -60) {
this.flipper.showPrevious();
return true;
}
return false;
}
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
}
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
// TODO Auto-generated method stub
return false;
}
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
}
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}