片段标准过渡没有动画 [英] Fragment standard transition not animating

查看:25
本文介绍了片段标准过渡没有动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 v4 android 兼容性库,使用专为 Android 2.2 及更高版本设备开发的片段开发平板电脑用户界面.

I'm using the v4 android compatibility library to develop a tablet UI using fragments specifically for Android 2.2 devices and up.

一切正常,除了我无法使用任何动画,甚至标准动画也不行.

Everything is working as it should, except that I can't get any animations to work, not even the standard animations.

代码:

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();

该片段没有使用过渡动画,而是冻结了大约一秒钟,然后消失了,新的出现了.

Instead of using a transit animation, the fragment freezes for about a second and the just disappears and the new one appears.

使用:

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 Motorola Xoom、2.3 Galaxy Tab 7"、2.2 模拟器,甚至 HTC G2 2.3.4 上进行了测试.

I read that the custom animation were broken in the compatibility library, but no one seems to be having issues with the standard transitions. I've tested this on a 3.2.1 Motorola Xoom, 2.3 Galaxy Tab 7", 2.2 emulator, and even on a HTC G2 with 2.3.4.

这里有什么问题?

推荐答案

经过多次反复试验,我终于得到了这个工作.

I finally got this to work after much trial and error.

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

First and foremost, get the lastest ACL, it did fix custom animations, and while this was not my exact problem, once those worked I ended up using them instead of standard transitions.

现在我正在使用:

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+ 的关键是执行以下操作:

The key to making it work on both Android 2.1, 2.2 and 2.3, as well as Android 3.0+ was to do the following:

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

片段动画现在适用于所有设备.如果您没有在应用程序标签中设置额外信息,动画将会发生,但以非常非常断断续续的方式发生,使其看起来好像根本没有发生.

Fragment animations now work on all devices. If you do not set the extra info in the application tag, the animation will occur, but in a very very choppy way, making it seem as though it did not happen at all.

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

Hope this helps someone in the future!

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

As a note, there are some API checking tools so you are sure you are not using any APIs that aren't available to you. I prefer to work on 2.1 so the IDE doesn't show anything I can't use, once I have stable code I jump back to compiling on 3.0

这篇关于片段标准过渡没有动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆