我正在尝试让一个自定义动画与我的片段一起工作。
我已经遵循了在线教程,但我得到了以下错误:
java.lang.RuntimeException:未知动画师姓名: translate
动画的XML如下:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%"
android:toXDelta="0"
android:duration="300" />
</set>
Java文件如下所示:
public void goCategory(View v) {
FragmentTransaction ft = fm.beginTransaction();
ft.setCustomAnimations(R.animator.anim_in_left, R.animator.anim_out_left);
ft.show(fragment);
ft.commit();
}
我在理解其他线程中的解决方案时遇到了困难。如果有人能帮我简化一下,我会很感激的。
发布于 2013-11-04 22:29:15
它不会工作,你应该使用对象动画
animator/slide_in_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:propertyName="x"
android:valueFrom="1000"
android:valueTo="0"
android:valueType="floatType" />
</set>
animator/slide_out_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:propertyName="x"
android:valueFrom="0"
android:valueTo="-1000"
android:valueType="floatType" />
</set>
类子类别
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
// return super.onCreateView(inflater, container, savedInstanceState);
View view = (ViewGroup) inflater.inflate(R.layout.product_frame, null);
getFragmentManager().beginTransaction()
.replace(R.id.sub_header, new Sub_Header()).commit();
getFragmentManager()
.beginTransaction()
.setCustomAnimations(R.animator.slide_in_left,
R.animator.slide_out_right, 0, 0)
.replace(R.id.product_frame, new Sub_Catagory_Grid()).commit();
view.getWidth();
return view;
}
发布于 2013-12-02 00:40:50
您可能混合了两个apis。有两种情况:
如果目标是3.0API以下的动画或使用R.animator.thing
).片段的:您必须使用旧的动画v4,也就是您正在使用的动画api(它们进入/,并且是使用本地片段的3.0以上的动画和:您必须使用新的动画api,即ObjectAnimators (它们进入animator/,并且是anim
发布于 2015-02-18 05:40:31
正如@minivac回答的那样,您正在混合两个API。请看一看安卓培训指南中的Display Card Flip Animations示例,以进一步了解如何向片段事务添加自定义动画。它恰好解决了你的问题。
https://stackoverflow.com/questions/17760299
复制相似问题