Android FragmentTransaction 自定义动画(Unknown Animator Name:Translate) [英] Android FragmentTransaction Custom Animation (Unknown Animator Name: Translate)

查看:38
本文介绍了Android FragmentTransaction 自定义动画(Unknown Animator Name:Translate)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用自定义动画来处理我的片段.

I'm trying to get a custom animation to work with my fragment.

我已按照在线教程进行操作,但出现以下错误:

I've followed the online tutorials but I've been getting the below error:

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

动画的 XML 如下:

The XML for the animation is below:

<?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 文件如下所示:

The Java file is shown below:

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

我无法理解其他线程中的解决方案.如果有人能帮我解释一下,我将不胜感激.

I'm having trouble understanding the solutions in the other threads. If someone could dumb it down for me, I'd really appreciate it.

推荐答案

不行,你应该使用 object animator

It will not work, you should use object animator

动画师/slide_in_left.xml

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>

动画师/slide_out_right.xml

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;

        }

这篇关于Android FragmentTransaction 自定义动画(Unknown Animator Name:Translate)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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