Android的FragmentTransaction自定义动画(未知动画名称:翻译) [英] Android FragmentTransaction Custom Animation (Unknown Animator Name: Translate)

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

问题描述

我试图让一个自定义动画与我的片段工作。

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

我无法理解,在其他线程的解决方案。 如果有人能哑下来对我来说,我真的AP preciate吧。

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

感谢

推荐答案

这是行不通的,你应该使用对象的动画

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>

类Subcatagory

Class Subcatagory

 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自定义动画(未知动画名称:翻译)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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