片段标准转换不是动画(Fragment standard transition not animating)

编程入门 行业动态 更新时间:2024-10-25 08:19:26
片段标准转换不是动画(Fragment standard transition not animating)

我正在使用v4 android兼容性库来开发平板电脑UI,使用专门针对Android 2.2设备的片段。

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

码:

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

而不是使用传输动画,片段会冻结约一秒钟,而消失,新的片段出现。

使用:

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测试了这一点。

这里有什么问题?

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?

最满意答案

我终于得到了这个工作,经过大量的尝试和错误。

首先,最重要的是获得最新的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编译。 在清单文件中,在应用程序标签内设置android:hardwareAccelerated="true" 。

片段动画现在适用于所有设备。 如果你没有在应用程序标签中设置额外的信息,那么动画将不会出现,但是以非常波动的方式,似乎没有发生任何事情。

希望这有助于未来的人!

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

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

更多推荐

本文发布于:2023-08-02 00:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1367974.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:片段   标准   动画   Fragment   transition

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!