gpt4 book ai didi

android - fragment 标准过渡没有动画

转载 作者:IT王子 更新时间:2023-10-28 23:52:16 25 4
gpt4 key购买 nike

我正在使用 v4 android 兼容性库来开发一个平板电脑 UI,它使用专门为 Android 2.2 及更高版本设备的 fragment 。

一切正常,除了我不能让任何动画工作,甚至是标准动画。

代码:

FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ABCFragment abcFragment = new ABCFragment();
ft.replace(R.id.main_frame_layout_fragment_holder,abcFragment);
ft.addToBackStack(null);
ft.commit();

fragment 没有使用过渡动画,而是卡住了大约一秒钟,然后就消失了,新的 fragment 出现了。

使用:

ft.setCustomAnimations(android.R.anim.slide_in_left,android.R.anim.slide_out_right);

也不行。

XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.synergygb.mycustomapp"
android:id="@+id/LinearLayout01" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical"
android:gravity="bottom">
<FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/main_frame_layout_fragment_holder">
</FrameLayout>
<!-- OTHER FIXED UI ELEMENTS-->
</RelativeLayout>

我了解到自定义动画在兼容性库中被破坏,但似乎没有人对标准过渡有任何问题。我已经在 3.2.1 摩托罗拉 Xoom、2.3 Galaxy Tab 7"、2.2 模拟器,甚至在 HTC G2 和 2.3.4 上进行了测试。

这里有什么问题?

最佳答案

经过多次尝试和错误,我终于让它工作了。

首先,获取最新的 ACL,它确实修复了自定义动画,虽然这不是我的确切问题,但一旦这些工作正常,我最终使用它们而不是标准过渡。

我现在正在使用:

ft.setCustomAnimations(android.R.anim.fade_in,android.R.anim.fade_out,android.R.anim.fade_in,android.R.anim.fade_out);

使其在 Android 2.1、2.2 和 2.3 以及 Android 3.0+ 上运行的关键是执行以下操作:

  • 确保您使用的 API 仅适用于您希望支持的最低 API 级别(在我的情况下为 2.1)。
  • 使用 Android 3.0 编译。
  • 在 list 文件中,在您的应用程序标签中设置 android:hardwareAccelerated="true"

fragment 动画现在适用于所有设备。如果你没有在应用程序标签中设置额外的信息,动画将会出现,但是以一种非常非常不稳定的方式,让它看起来好像根本没有发生。

希望这对将来的某人有所帮助!

请注意,有一些 API 检查工具,因此您可以确定您没有使用任何您无法使用的 API。我更喜欢在 2.1 上工作,所以 IDE 不会显示任何我不能使用的东西,一旦我有稳定的代码,我就会跳回在 3.0 上编译

关于android - fragment 标准过渡没有动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7718111/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com