Transparent software navigation using viewflipper and gestures

Source: Internet
Author: User
Package COM. nd. activitydemo; import android. app. activity; import android. OS. bundle; import android. util. log; import android. view. gesturedetector; import android. view. motionevent; import android. view. view; import android. view. gesturedetector. ongesturelistener; import android. view. view. onclicklistener; import android. view. viewgroup. layoutparams; import android. view. animation. animationutils; import android. widge T. imageview; import android. widget. viewflipper; public class activitydemoactivity extends activity implements ongesturelistener {/** called when the activity is first created. */gesturedetector failed; // Private Static final int scroll_min_distance = 160; // Private Static final int timeout = 10; private viewflipper VF; @ overridepublic void oncreate (bundle savedinstancestate) {sup Er. oncreate (savedinstancestate); settheme (R. style. transparent); setcontentview (R. layout. transparent); VF = (viewflipper) findviewbyid (R. id. VF); VF. addview (addimagebyid (R. drawable. guardpic1), new layoutparams (layoutparams. fill_parent, layoutparams. wrap_content); VF. addview (addimagebyid (R. drawable. guardpic2), new layoutparams (layoutparams. fill_parent, layoutparams. wrap_content); mgesturedetector = new G Esturedetector (activitydemoactivity. this);} // test the gesture at Development @ overridepublic Boolean ontouchevent (motionevent event) {// todo auto-generated method stubboolean retvalue = mgesturedetector. ontouchevent (event); int action = event. getaction (); If (Action = motionevent. action_up) {// helper Method for lifted finger} else if (Action = motionevent. action_cancel) {} return retvalue;} @ overridepublic Boolean Ondo Wn (motionevent e) {// todo auto-generated method stubreturn false;} @ overridepublic Boolean onfling (motionevent E1, motionevent E2, float velocityx, float velocityy) {// todo auto-generated method stublog. I ("Fling", "fling happened! "); If (e1.getx ()-e2.getx ()> 120) {This. VF. setinanimation (animationutils. loadanimation (this, R. anim. push_left_in); this. VF. setoutanimation (animationutils. loadanimation (this, R. anim. push_left_out); this. VF. shownext (); Return true;} else if (e1.getx ()-e2.getx () <-120) {This. VF. setinanimation (animationutils. loadanimation (this, R. anim. push_right_in); this. VF. setoutanimation (animationutils. loadanimation (this, R. anim. push_right_out); this. VF. showprevious (); Return true;} return true;} @ overridepublic void onlongpress (motionevent e) {// todo auto-generated method stub} @ overridepublic Boolean onscroll (motionevent E1, motionevent E2, float distancex, float distancey) {// todo auto-generated method stublog. I ("motionevent", "onscroll ......... "); // parameter explanation: // E1: 1st action_down motionevent // E2: The last action_move motionevent // velocityx: The moving speed on the X axis, pixel/second // velocityy: The moving speed on the Y axis, pixel/second // trigger condition: // The coordinate displacement of the X axis is greater than that of scroll_min_distance, and the moving speed is greater than scroll_min_velocity pixels/S // If (e1.getx ()-e2.getx ()> scroll_min_distance // & math. ABS (distancex)> scroll_min_velocity) {// fling left // IV. setbackgroundresource (R. drawable. guardpic2); //} else if (e2.getx ()-e1.getx ()> scroll_min_distance // & math. ABS (distancex)> scroll_min_velocity) {// fling right/IV. setbackgroundresource (R. drawable. detailpageguideinfo); //} return false;} @ overridepublic void onshowpress (motionevent e) {// todo auto-generated method stub} @ overridepublic Boolean onsingletapup (motionevent E) {// todo auto-generated method stubactivitydemoactivity. this. finish (); Return false;} public view addimagebyid (int id) {imageview IV = new imageview (this); IV. setimageresource (ID); Return IV ;}}

Layout file:

<?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"    ><ViewFlipper  android:id="@+id/vf"    android:layout_width="fill_parent"     android:layout_height="fill_parent"     /></LinearLayout>

References:

Viewflipper animation use http://www.iteye.com/topic/569493

Viewflipper combined with the gesture ongesturelistener to create the sliding switching effect http://blog.csdn.net/feng88724/article/details/6170694androidhand page flip effect http://www.iteye.com/topic/712644

Android slide effects custom http://www.apkbus.com/android-13210-1-1.html

[Experience sharing] the use of Flipper Android http://wap.devdiv.com/thread-84867-1-1.html

Complete source code: http://download.csdn.net/detail/sxsj333/3615788

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.