bli*_*uff 45 animation android android-fragments android-support-library
我正在使用v4 android兼容性库来开发平板电脑用户界面,使用专门针对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();
Run Code Online (Sandbox Code Playgroud)
片段冻结大约一秒钟而不是使用过渡动画,而刚刚消失并出现新的片段.
使用:
ft.setCustomAnimations(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
Run Code Online (Sandbox Code Playgroud)
也不起作用.
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>
Run Code Online (Sandbox Code Playgroud)
我读到自定义动画在兼容性库中被破坏了,但似乎没有人遇到标准转换的问题.我已经在3.2.1摩托罗拉Xoom,2.3 Galaxy Tab 7",2.2仿真器,甚至在2.4.4的HTC G2上进行了测试.
这可能有什么问题?
bli*_*uff 38
经过多次试验和错误,我终于让它工作了.
首先,获得最新的ACL,它确实修复了自定义动画,虽然这不是我的确切问题,但一旦这些工作我最终使用它们而不是标准转换.
现在我使用:
ft.setCustomAnimations(android.R.anim.fade_in,android.R.anim.fade_out,android.R.anim.fade_in,android.R.anim.fade_out);
Run Code Online (Sandbox Code Playgroud)
使其适用于Android 2.1,2.2和2.3以及Android 3.0+的关键是执行以下操作:
android:hardwareAccelerated="true"在应用程序标记内设置.片段动画现在适用于所有设备.如果你没有在应用程序标签中设置额外的信息,那么动画就会出现问题,但是以一种非常不稳定的方式,让它看起来根本没有发生.
希望这有助于未来的人!
请注意,有一些API检查工具,因此您确定不使用任何不可用的API.我更喜欢在2.1上工作,所以IDE没有显示我无法使用的任何东西,一旦我有稳定的代码我就跳回到3.0上的编译
dvd*_*dvd 34
尝试再次获取最新的ACL,他们已修复它:http: //code.google.com/p/android/issues/detail?id = 15623#c19
另外我注意到对于setCustomAnimations,它需要在事务调用之前设置,如replace才能生效.
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.in_from_left, R.anim.out_to_right, R.anim.in_from_right, R.anim.out_to_left);
ft.replace(android.R.id.content, newFrag);
ft.addToBackStack(null);
ft.commit();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
38121 次 |
| 最近记录: |