Android touch screen sliding event Summary

Source: Internet
Author: User

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

Related Article

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.