首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >安卓FragmentTransaction自定义动画(未知动画师名称: Translate)

安卓FragmentTransaction自定义动画(未知动画师名称: Translate)
EN

Stack Overflow用户
提问于 2013-07-20 16:25:02
回答 3查看 54.7K关注 0票数 71

我正在尝试让一个自定义动画与我的片段一起工作。

我已经遵循了在线教程,但我得到了以下错误:

java.lang.RuntimeException:未知动画师姓名: translate

动画的XML如下:

代码语言:javascript
复制
<?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文件如下所示:

代码语言:javascript
复制
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();
}

我在理解其他线程中的解决方案时遇到了困难。如果有人能帮我简化一下,我会很感激的。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-11-04 22:29:15

它不会工作,你应该使用对象动画

animator/slide_in_left.xml

代码语言:javascript
复制
<?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

代码语言:javascript
复制
<?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>

类子类别

代码语言:javascript
复制
 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;

        }
票数 115
EN

Stack Overflow用户

发布于 2013-12-02 00:40:50

您可能混合了两个apis。有两种情况:

如果目标是3.0API以下的动画或使用R.animator.thing).片段的:您必须使用旧的动画v4,也就是您正在使用的动画api(它们进入/,并且是使用本地片段的3.0以上的动画和:您必须使用新的动画api,即ObjectAnimators (它们进入animator/,并且是anim

票数 117
EN

Stack Overflow用户

发布于 2015-02-18 05:40:31

正如@minivac回答的那样,您正在混合两个API。请看一看安卓培训指南中的Display Card Flip Animations示例,以进一步了解如何向片段事务添加自定义动画。它恰好解决了你的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17760299

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档