effect is finished to achieve this effect. 1. The layout file The main interface uses the following layout:
<?xml version= "1.0" encoding= "Utf-8"?> "<framelayout xmlns:android=" http:// Schemas.android.com/apk/res/android "android:layout_width=" fill_parent "android:layout_height=" Fill_parent "an droid:orientation= "vertical" > <viewflipper android:id= "@+id/viewflipper1" android:layout_width= "fill_p"
Arent "android:layout_height=" fill_parent "> </ViewFlipper> <linearlayout android:orientation= "Horizontal" android:layout_width= "Wrap_content" android:layout_gravity= "B"
Ottom|center_horizontal "android:layout_height=" wrap_content "> <imageview Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:src= "@drawabl E/da "android:id=" @+id/imageview1 "/> <imageview android:layo Ut_width= "Wrap_content" android:layout_height= "Wrap_content" android:src= "@drawable/xiao" android:id= "@+id/imageview2" /> <imageview android:layout_width= "wrap_content" android:layout_height= "wrap" _content "android:src=" @drawable/xiao "android:id=" @+id/imageview3 "/> < ImageView android:layout_width= "wrap_content" android:layout_height= "Wrap_content" and roid:src= "@drawable/xiao" android:id= "@+id/imageview4"/> </linearlayou T> </framelayout>
A simple introduction to the layout of the file: The outermost is a framelayout, using Framelayout is to be the following four points on the viewflipper above. The layoutlayout is centered below the framelayout and horizontally.
Use of 2.ViewFlipper
Flipper = (viewflipper) This.findviewbyid (r.id.viewflipper1);
Flipper.addview (Addimageview (r.drawable.png1o));
Flipper.addview (Addimageview (R.DRAWABLE.PNG2O));
Flipper.addview (Addimageview (r.drawable.png3o));
Flipper.addview (AddView ());
Declare an Viewflipper object in the activity, found in the layout. Add three pictures to Viewflipper, plus a view, which is derived from the XML layout file. The layout files are as follows:
<?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"
>
<button
android:id= "@+id/button" android:layout_width= "WRAP_"
Content "
android:layout_height=" wrap_content "
android:layout_marginbottom=" 45DP "
android:text=" Enter the program "
android:textcolor=" #3E3E3E "android:layout_gravity=" center_horizontal "
/>
</ Linearlayout>
In this layout file, there is a button that is used to jump the activity.
Declares a Gesturedetector object in the activity, allocating memory in the OnCreate method.
detector = new Gesturedetector (this);
Using this as a parameter, you should make the Activity class Impllements Ongesturelistener interface. Rewrite several methods. Overrides the Ontouchevent method of the parent class, written as follows in this method:
@Override Public
Boolean ontouchevent (Motionevent event) {
//TODO auto-generated method stub
return This.detector.onTouchEvent (event);
}
This allows detector to accept the message response.
In the implementation of Ongesturelistener method to determine the user's sliding to switch interface:
@Override public boolean onfling (Motionevent E1, motionevent E2, float Velocityx, float v
Elocityy) {System.out.println ("in------------>>>>>>>");
if (E1.getx ()-e2.getx () >) {if (I < 3) {i++;
SetImage (i);
This.flipper.setInAnimation (Animationutils.loadanimation (this, r.anim.animation_right_in));
This.flipper.setOutAnimation (Animationutils.loadanimation (this, r.anim.animation_left_out));
This.flipper.showNext ();
return true;
else if (E1.getx ()-E2.getx () < -120) {if (i > 0) {i--;
SetImage (i);
This.flipper.setInAnimation (Animationutils.loadanimation (this, r.anim.animation_left_in));
This.flipper.setOutAnimation (Animationutils.loadanimation (this, r.anim.animation_right_out));
This.flipper.showPrevious ();
return true;
return false; } void setimage (int i) {for (int j=0;j<4;j++) {if (j!=i) iamgeS[j].setimageresource (R.drawable.xiao);
else Iamges[j].setimageresource (R.DRAWABLE.DA); }
}
Change the image of the following four small imageview when the interface is switched. Toggle animations in the Res/anim folder