Android Three slide effects Gesture Recognition left and right slide effect left and right slide guide effect fade Show button left and right slide Effect

Source: Internet
Author: User
Tags event listener
Gesture Recognition

1. oncreateAddGesturedetector mgesturedetector;

 //Listen for gesture events

Mgesturedetector = new gesturedetector (this, ongesturelistener );

2.//Implement event handling

Ongesturelistener = new ongesturelistener (){

 //Add unimplemented Methods

};

 3.RewriteOntouchEvent

//Handle touch events with the gesture detection Interface

Public Boolean ontouchevent (motionevent event ){

Return mgesturedetector. ontouchevent (event );

}

Slide between left and right

1. Define the viewflipper control in XML;

2. Override the ontouchevent method to capture touch events.

View code

3. WritePush_left_in.xml,Push_left_out.xml,Push_right_in.xml,The push_right_out.xml file is used to show the sliding effect;

4. Define ongesturelistener in the activity, override the onfling method, judge the left and right sliding Based on the Coordinate Difference of E1 and E2, and write the sliding effect in it.

View code

 @ Override  Public   Boolean Onfling (motionevent E1, motionevent E2, Float  Velocityx,  Float  Velocityy ){ If (E1.getx ()-e2.getx () & gt; 120 ){  This . Flipper. setinanimation (animationutils. loadanimation ( This  , R. anim. push_left_in ));  This . Flipper. setoutanimation (animationutils. loadanimation ( This  , R. anim. push_left_out ));  This  . Flipper. shownext ();  Return   True ;}  Else   If (E1.getx ()-e2.getx () <-120 ){  This . Flipper. setinanimation (animationutils. loadanimation ( This  , R. anim. push_right_in ));  This . Flipper. setoutanimation (animationutils. loadanimation ( This  , R. anim. push_right_out ));  This  . Flipper. showprevious (); Return   True  ;}  Return   False  ;} 

Download project: guideviewtest.rar

From: http://www.cnblogs.com/hanyonglu/archive/2012/02/13/2349827.html

Sliding Guide Effect

1. JoinAndroid-support-v4.jar,For android-support-v4.jar details, you can visit the Official Google Website:Http://developer.android.com/sdk/compatibility-library.html;

2. in XML, use framelayout to complete the layout, and place the viewpager and guide icons.

View code

<? 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" Android: Orientation = "Vertical"> < Linearlayout Android: layout_width = "Match_parent" Android: layout_height = "Wrap_content" Android: Orientation = "Vertical"> <include layout = "@ layout/item_header"/> < Android. Support. v4.view. viewpager Android: ID = "@ + ID/guidepages" Android: layout_width = "Fill_parent"Android: layout_height = "Wrap_content"/> </linearlayout> <! -- Guide icon --> < Linearlayout Android: ID = "@ + ID/viewgroup" Android: layout_width = "Fill_parent" Android: layout_height = "Wrap_content" Android: layout_gravity = "Bottom" Android: layout_marginbottom = "40dp" Android: gravity = "Center_horizontal" Android: Orientation = "Horizontal"> </linearlayout> </framelayout>

3. Add the page layout to the View list,There are several layout pages with a few dot images,Set the dot image layout through the for loop;

View code

 //  Add to view list Layoutinflater Inflater = Getlayoutinflater (); pageviews = New Arraylist <View> (); Pageviews. Add (Inflater. Inflate (R. layout. item05,  Null  ); Pageviews. Add (Inflater. Inflate (R. layout. item06,  Null  ); Pageviews. Add (Inflater. Inflate (R. layout. item01, Null  ); Pageviews. Add (Inflater. Inflate (R. layout. item02,  Null  ); Pageviews. Add (Inflater. Inflate (R. layout. item03,  Null  ); Pageviews. Add (Inflater. Inflate (R. layout. item04,  Null  ));  //  There are several layout pages with just a few bullets Imageviews = New  Imageview [pageviews. Size ()];  //  Set the dot image layout through the For Loop For ( Int I = 0; I <pageviews. Size (); I ++ ) {Imageview = New Imageview (guideviewtestactivity. This  ); Imageview. setlayoutparams (  New Layoutparams (20, 20 ); Imageview. setpadding ( 20, 0, 20, 0 ); Imageviews [I] = Imageview;  If (I = 0 ){ //  The first image is selected by default.  Imageviews [I]. setbackgroundresource (R. drawable. page_indicator_focused );}  Else  {Imageviews [I]. setbackgroundresource (R. drawable. page_indicator);} group. addview (imageviews [I]);} 

4,Data adapter and page switching event listener

5,In the guidepagechangelistener of the event listener on the guide page, make sure that the dot picture changes when switching the page.

View code

@ OverridePublic VoidOnpageselected (IntArg0 ){For(IntI = 0; I <imageviews. length; I ++) {Imageviews [arg0]. setbackgroundresource (R. drawable. page_indicator_focused );If(Arg0! =I) {imageviews [I]. setbackgroundresource (R. drawable. page_indicator );}}}

Download project: myandroidflip.rar

From: http://www.cnblogs.com/hanyonglu/archive/2012/04/07/2435589.html

Sliding between left and right of the fade button

1. Define the viewflipper control in XML and add multiple page la s to it. You can also useCodeAddview method of viewflipper;

2. Write the push_left_in.xml, push_left_out.xml, push_right_in.xml, and push_right_out.xml files;

3. Add Permissions

 
<Uses-Permission Android: Name = "android. Permission. system_alert_window"/>

4. initialize the Left and Right floating buttons in the activity, create the left and right buttons, and set listener events (replace images );

View code

 /**  * Initialize the floating button  */      Private   Void  Initimagebuttonview (){  //  Obtain windowmanager WM = (windowmanager) getapplicationcontext (). getsystemservice ("window" );  //  Set parameters for layoutparams Wmparams = New  Windowmanager. layoutparams ();  //  Set Window Type Wmparams. type = Layoutparams. type_phone;  //  Set the image format. The effect is transparent to the background. Wmparams. format = Pixelformat. rgba_8888;  // Set window flag Parameters Wmparams. Flags = Layoutparams. flag_not_touch_modal | Layoutparams. flag_not_focusable;  //  Set the initial values of X and Y Wmparams. x = 0 ; Wmparams. Y = 0 ;  //  Set window length and width data Wmparams. width = 50 ; Wmparams. Height = 50 ;  // Create left and right buttons  Createleftbuttonview (); createrightbuttonview ();} 

5. Override the ontouchevent event to trigger the show and hide floating button events (motionevent. action_down and motionevent. action_up );

6. Use threads to control the transparency of the floating button (alpha and invalidate)

Download project: mypagefliper.rar

From: http://www.cnblogs.com/hanyonglu/archive/2012/02/13/2350171.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.