Android:如何在活动之间切换,例如在家庭应用程序中切换桌面?

发布于 2024-09-09 02:01:16 字数 730 浏览 5 评论 0原文

我正在开发一个 Android 应用程序,它具有三个非常相似的活动。我希望用户能够通过在屏幕上左右滑动来在它们之间进行切换。 到目前为止,这就是我的管理方式:

我关注了这篇帖子

然后我以这种方式更改了 onSwipe() 方法:

@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);
 }

它有效,但我对此并不完全满意。此外,我不知道这是否是正确的方法。

我希望在切换桌面时有一种类似于家庭应用程序的行为。因此,我想要一个更流畅的动画以及从正确方向调用的活动的外观,例如。向右滑动时从屏幕左侧。

有什么提示吗?非常感谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岛歌少女 2024-09-16 02:01:17

虽然最好将它们作为三个单独的 Activity,但我见过人们使用 ViewFlipper 在单个 Activity 中实现类似的效果。

这是一个包含更多信息的链接:
http://www.inter- fusionr.com/2009/07/android-transistions-slide-in-and-slide.html

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

风和你 2024-09-16 02:01:16

主屏幕不会在活动之间滚动,它只会在不同视图之间滚动,如您在 其源代码(第298行是改变屏幕的地方)。

如果您在活动之间切换,您将受到用户配置和操作的支配。设备的能力决定了转换期间显示会发生什么,因此您无能为力。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文