Screen switching refers to switching on the screen of the same Activity.
Slip events are implemented using GestureDetector and OnGestureListener. ViewFlipper is inherited to FrameLayout, so it is a Layout where multiple views can be placed. In this example, only one BUTTON is put on the first page. When the screen goes down, only one TEXTVIEW is put on each page.
Page:
View plaincopy to clipboardprint?
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<ViewFlipperandroid: id = "@ + id/ViewFlipper01"
Android: layout_width = "fill_parent" android: layout_height = "fill_parent">
</ViewFlipper>
</LinearLayout>
Activity Code:
View plaincopy to clipboardprint?
Package com. yfz;
Import android. app. Activity;
Import android. OS. Bundle;
Import android. util. Log;
Import android. view. GestureDetector;
Import android. view. MotionEvent;
Import android. view. View;
Importandroid. view. GestureDetector. OnGestureListener;
Import android. view. ViewGroup. LayoutParams;
Importandroid. view. animation. AnimationUtils;
Import android. widget. Button;
Import android. widget. ExpandableListView;
Import android. widget. TextView;
Import android. widget. ViewFlipper;
Public class Flip extends Activity implements OnGestureListener {
PrivateGestureDetector detector;
PrivateViewFlipper flipper;
@ Override
Public voidonCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
Flipper
= (ViewFlipper) this. findViewById (R. id. ViewFlipper01 );
Flipper. addView (addButtonByText ("button"), new
LayoutParams (LayoutParams. FILL_PARENT, LayoutParams. WRAP_CONTENT ));
Detector
= New gesturedetector (this );
}
Public viewaddbuttonbytext (string text ){
Button
BTN = newbutton (this );
Btn. setText (text );
Returnbtn;
}
Public ViewaddTextByText (String text ){
Textview
TV = newtextview (this );
TV. settext (text );
TV. setgravity (1 );
Returntv;
}
@ Override
Publicboolean ontouchevent (motionevent event ){
Log. I ("Fling ",
"Activity ontouchevent! ");
Return
This. detector. ontouchevent (event );
}
@ Override