Android Activity sliding around the page or the effect of switching to achieve

2011-05-23  来源:本站原创  分类:Mobile  人气:120 

Android desktop can use hand signals for left and right sliding switch. Or you used a certain iReader gesture impressed by its rich bar. Now look at their own how to switch it between multiple Activy

1, the need to inherit OnGestureListener and OnDoubleTapListener, as follows:

public class ViewSnsActivity extends Activity implements OnTouchListener, OnGestureListener

2, the definition of adding mGestureDetector and ViewSnsActivity the onCreate function into their page layout setOnTouchListener events

GestureDetector mGestureDetector;
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view_sns_activity);

        mGestureDetector = new GestureDetector((OnGestureListener) this);
        LinearLayout viewSnsLayout = (LinearLayout)findViewById(R.id.viewSnsLayout);
        viewSnsLayout.setOnTouchListener(this);
        viewSnsLayout.setLongClickable(true);
    }

3, function overloading onFling

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                        float velocityY) {

                if (e1.getX()-e2.getX() > snsConstant.getFlingMinDistance()
                                && Math.abs(velocityX) > snsConstant.getFlingMinVelocity()) {

//                       Switch Activity
//                      Intent intent = new Intent(ViewSnsActivity.this, UpdateStatusActivity.class);
//                      startActivity(intent);
                        Toast.makeText(this, " Left hand gestures ", Toast.LENGTH_SHORT).show();
                } else if (e2.getX()-e1.getX() > snsConstant.getFlingMinDistance()
                                && Math.abs(velocityX) > snsConstant.getFlingMinVelocity()) {

//                       Switch Activity
//                      Intent intent = new Intent(ViewSnsActivity.this, UpdateStatusActivity.class);
//                      startActivity(intent);
                        Toast.makeText(this, " The right gesture ", Toast.LENGTH_SHORT).show();
                }

                return false;
        }

Which SnsConstant as follows:

public class SnsConstant {
    private static final int FLING_MIN_DISTANCE = 50;
    private static final int FLING_MIN_VELOCITY = 0;

        public static int getFlingMinDistance() {
                return FLING_MIN_DISTANCE;
        }
        public static int getFlingMinVelocity() {
                return FLING_MIN_VELOCITY;
        }
}

4, function overloading onTouch

public boolean onTouch(View v, MotionEvent event) {
                return mGestureDetector.onTouchEvent(event);
        }

Specific meaning to write it tomorrow

相关文章
  • Android Activity sliding around the page or the effect of switching to achieve 2011-05-23

    Android desktop can use hand signals for left and right sliding switch. Or you used a certain iReader gesture impressed by its rich bar. Now look at their own how to switch it between multiple Activy 1, the need to inherit OnGestureListener and OnDou

  • android Activity description 2010-04-30

    Activity in android development is very important, in an application, each display screen is a Activity. So learning android, must have a certain understanding of the Activity. In other forums there are some on the Activity of the introduction, I am

  • Android Activity type application skills sharing 2010-05-27

    Android Activity class in the Android operating system, applications are often important. So how can the right to operate in the application of this work? In an application, each display screen is a Activity. So learning Android, must have some under

  • Fourth Lecture - Android Activity of the preliminary 2010-06-18

    Fourth Lecture - Android Activity of the initial

  • Fourth Lecture - Android Activity of the initial 2010-06-18

    Fourth Lecture - Android Activity of the initial

  • Android android activity set in full screen and get the screen width and height 2010-08-23

    android activity set in full screen requestWindowFeature (Window.FEATURE_NO_TITLE); Android get screen width and height int screenWidth; int screenHeight; WindowManager windowManager = getWindowManager (); Display display = windowManager.getDefaultDi

  • Android Activity Introduction to Life Cycle 2010-10-22

    Android activity of the life cycle activity class in the android.app package, inheritance system is as follows: 1.java.lang.Object 2.android.content.Context 3.android.app.ApplicationContext 4.android.app.Activity activity alone, for processing user.

  • Used in the Android Activity, Service, Broadcast, BroadcastReceiver 2010-12-06

    Describes the use of the Android Activity, Service, Broadcast, BroadcastReceiver Activities (Activity) - for the performance of functional services (Service) - the equivalent of running in the background Activity Radio (Broadcast) - used to send broa

  • Android: Activity. Process. BoradcastReceiver life cycle 2010-12-24

    Android Activity and processes in the life cycle is a very important issue. Android have taken the process like garbage collection mechanism, which means that even if the user quit the program, the process may still exist in the system. This will dir

  • [Zhuantie] Android Activity beautiful custom jump effect 2011-05-31

    Jump to customize Android Activity beautiful effect Jump when the two Activity, custom mouse gestures: Intent intent = new Intent (FirstActivity.this, SecondActivity.class); startActivityForResult (intent, 11); / / Add interface switching effect, not

  • Android Activity之间传递图片(Bitmap)的方法 2014-10-06

    这篇文章介绍了Android Activity之间传递图片(Bitmap)的方法,有需要的朋友可以参考一下 在Android开发中:Activity之间传递参数是常见的事:如果我们要在Activity之间传递图片: 1.MainActivity中包括一个ImageView:当我们点击ImageView时:把图片传递给另外一个Activity MainActivity的主要代码: Intent intent=new Intent(MainActivity.this,TranActivity.cla

  • Android Activity切换(跳转)时出现黑屏的解决方法 分享 2015-01-04

    Android Activity切换(跳转)时出现黑屏的解决方法 分享,需要的朋友可以参考一下 在两个Activity跳转时,由于第二个Activity在启动时加载了较多数据,就会在启动之前出现一个短暂的黑屏时间,解决这个问题比较简单的处理方法是将第二个Activity的主题设置成透明的,这样在启动第二个Activity时的黑屏就变成了显示第一个Activity界面.这个分两步完成: 第一步:xxx/res/values/styles.xml中加入自定义Activity的Theme,如下所示:

  • Android Activity 调用startActivityForResult之后被销毁? 2014-09-28

    Android Activity 调用startActivityForResult之后调用的Activity被销毁的问题 最近在华为的手机上面发现Activity调用startActivityForResult后返回结果时,调用的Activity都会被重新创建,也就是Activity被销毁了. 在网上经过一番查找,发现有哥们说在手机开发人员选项里面有这么一项"不保留活动"被勾上了, 一看还真是. 把那个勾去掉一切又恢复正常了.

  • Android必备:Android Activity的生命周期 2014-11-28

    链接地址:http://www.xx566.com/detail/124.html 在Android应用程序组成中, 我们了解到了Android组件Activity的重要性,它是Android应用的表示层,负责应用的UI展现,直接与用户进行交互,与Servlet 类似,Activity也有自己的生命周期,接下来,我们就来简单觉得了解一下Android Activity的生命周期. 关于Android Activity生命周期,网上有许多经典的介绍,不过大神写的永远是大神的,只有自己详尽的理解和总

  • CSS control page text larger effect 2010-03-31

    Css web page using the link buttons to zoom in to do good results, it's difficult to relative positioning, so this relative positioning of CSS solves this problem better than to use absolute positioning, more powerful to achieve whatever you put the

  • android activity in the Jump to page 2010-08-19

    Intent it = new Intent (Intent.ACTION_VIEW); it.setData (Uri.parse (" http://www.pingan.com/ ")); / / need to turn around the inside of the rul it = Intent.createChooser (it, null); startActivity (it);

  • Android Activity / Service Intent communication Jump 2010-03-29

    The first approach, using action to jump. 1, using Action jump, if there is a program AndroidManifest.xml an Activity in a defined segment of IntentFilter that contains the same Action then this Intent with this goal Action matches. If this IntentFil

  • Android Activity and Intent Mechanism Study Notes 2010-03-29

    Activity Android in, Activity is the root of all programs, all of processes are running in the Activity among, Activity has its own life cycle (see http://www.cnblogs.com/feisky/archive/2010/01/01/1637427 . html, controlled by the system life cycle,

  • Android Activity and Mechanism of learning notes Intent 2010-03-17

    Activity Android in, Activity is the basic of all procedures, all of processes are being run in Activity, Activity has its own life cycle (see http://www.cnblogs.com/feisky/archive/2010/01/01/1637427 . html, controlled by the system life cycle, the p

  • Android Activity and Intent mechanism study notes (change) 2010-08-14

    Activity Android in, Activity is the basic of all procedures, all of processes are being run in Activity, Activity has its own life cycle (see http://www.cnblogs.com/feisky/archive/2010/01/01/1637427 . html, controlled by the system life cycle, the p