片段标准的过渡不是动画 [英] Fragment standard transition not animating

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

问题描述

我使用的是V4 Android的兼容性库使用片段专门为Android 2.2设备,并达到开发平板电脑的用户界面。

一切工作,因为它应该,但我不能让任何动画工作,甚至没有标准的动画。

code:

  FragmentTransaction英尺= getSupportFragmentManager()的BeginTransaction()。
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    ABCFragment abcFragment =新ABCFragment();
    ft.replace(R.id.main_frame_layout_fragment_holder,abcFragment);
    ft.addToBackStack(空);
    ft.commit();
 

而不是使用一个中转动画,显示的片段冻结约一秒钟,刚刚消失,新的。

使用:

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

也不起作用。

XML:

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
的xmlns:程序=htt​​p://schemas.android.com/apk/res/com.synergygb.mycustomapp
机器人:ID =@ + ID / LinearLayout01机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT机器人:方向=垂直
机器人:重力=底和GT;
<的FrameLayout机器人:layout_width =FILL_PARENT机器人:layout_height =FILL_PARENT机器人:ID =@ + ID / main_frame_layout_fragment_holder>
< /的FrameLayout>
<! - 其他固定资产的UI元素 - >
< / RelativeLayout的>
 

我读的自定义动画是在兼容性库坏了,但没有人似乎有与标准过渡的问题。我已经在3.2.1摩托罗拉Xoom,2.3的Galaxy Tab 7,2.2模拟器测试这一点,即使是在HTC G2 2.3.4。

什么在这里可能是错了吗?

解决方案

我终于得到了这多的反复试验后工作。

首先,获取最新的ACL,它没有固定的自定义动画,虽然这wasnt我确切的问题,一旦这些工作,我结束了使用标准的过渡,而不是他们。

现在即时通讯使用:

<$p$p><$c$c>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,以及安卓3.0+是要做到以下几点:

  • 确保只使用API​​'s提供给您想支持(在我的情况下,2.1)的最低API级别。
  • 在编译采用Android 3.0。
  • 在清单文件,设置机器人:hardwareAccelerated =真正的应用程序标记中

动画片段现在的工作在所有设备上。如果你不设置在应用程序标签的额外的信息,该动画将ocurr,但在一个非常非常不连贯的方式,使它看起来它并没有出现在所有。

希望这可以帮助别人的未来!

作为一个说明,有一些API检查工具,让你确信你的arent使用的arent提供给您任何的API。我preFER工作在2.1这样的IDE犯规显示任何东西我不能使用,一旦我有稳定的code我跳回编制的3.0

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.

Code:

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.

Using:

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

doesn't work either.

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>

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.

What could be wrong here?

解决方案

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

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

Right now im using:

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

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:

  • Make sure you are using ONLY API´s available to the lowest API LEVEL you wish to support (in my case 2.1).
  • Compile using Android 3.0.
  • In the manifest file, set android:hardwareAccelerated="true" inside your application tag.

Fragment animations now work on all devices. If you dont set the extra info in the application tag, the animation will ocurr, but in a very very choppy way, making it seem it didnt happen at all.

Hope this helps someone in the future!

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

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

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