Android: How to switch between Activities like switching desktops in Home app?

不羁岁月 提交于 2019-12-09 11:49:35

问题


I'm developing an Android Application that has three very similar Activities. I would like the user to be able to switch between them by swiping left and right on the screen. This is how I managed that up to now:

I followed this post

Then I changed the method onSwipe() in this way:

@Override
 public void onSwipe(int direction) {
  Intent intent = new Intent();

  switch (direction) {

  case SimpleGestureFilter.SWIPE_RIGHT:
   intent.setClass(this, TodoTodaySheet.class);
   break;
  case SimpleGestureFilter.SWIPE_LEFT:
   intent.setClass(this, TrashSheet.class);
   break;

  }
  startActivity(intent);
 }

It works but I'm not completely satisfied with this. Moreover, I don't know if this is the correct approach.

I would like to have a behavior like the one on Home apps, when switching desktop. Therefore I would like a smoother animation and the appearance of the called activity from the right direction, eg. from the left side of the screen when swiping on the right.

Any hints? Thank you very much.


回答1:


The home screen doesn't scroll between activities it only scrolls between differing views as you can see in its' source code (line 298 is where the screens are changed).

If you're switching between activities you're at the mercy of the users configuration & the devices abilities as to what happens to the display during the transition, so there isn't a lot you can do.




回答2:


While it's probably best to have them as three separate Activities, I've seen people use a ViewFlipper to achieve a similar effect in a single Activity.

Here's a link with a little more information about it: http://www.inter-fuser.com/2009/07/android-transistions-slide-in-and-slide.html



来源:https://stackoverflow.com/questions/3218733/android-how-to-switch-between-activities-like-switching-desktops-in-home-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!