【问题标题】:unknown animator name : translate未知动画师姓名:翻译
【发布时间】:2014-11-08 06:09:31
【问题描述】:

在为 Fragment Transaction 设置动画时出现此错误。

片段 A xml:

<FrameLayout
android:id="@+id/relative"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp"
android:background="#009688">

<RelativeLayout
    android:layout_weight="0.5"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:id="@+id/linear">

    <TextView
        android:layout_marginTop="35dp"
        android:id="@+id/mission"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="MISSION"
        android:textColor="#ffffff"
        android:textSize="70dp"
        android:gravity="center_horizontal"/>

    <TextView
        android:layout_below="@+id/mission"
        android:id="@+id/notimpossible"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="NOT IMPOSSIBLE"
        android:textColor="#ffffff"
        android:textStyle="bold"
        android:textSize="35dp"
        android:gravity="center_horizontal"/>

</RelativeLayout>

<RelativeLayout
    android:padding="10dp"
    android:layout_weight="0.5"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_below="@+id/linear">

    <TextView
        android:id="@+id/random_main"
        android:textSize="20dp"
        android:textColor="@color/white"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</RelativeLayout>


<TextView
    android:id="@+id/ahead"
    android:clickable="true"
    android:layout_marginBottom="35dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:text="Go Ahead! "
    android:textSize="23dp"
    android:textColor="@drawable/text_focus_white"
    android:layout_marginRight="8dp"
    android:layout_gravity="right"/>


</LinearLayout>
</FrameLayout>

片段 B xml:

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cddc39">

片段A到片段B的交易代码:

    fragB frag = new fragB();
    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.addToBackStack("wTF");
    ft.setCustomAnimations(R.anim.slide_out_to_right, R.anim.slide_in_from_right);
    ft.replace(R.id.main,fragB);
    ft.commit();

</FrameLayout>

这里是动画 xmls

Slide_in_from_right :

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
  <translate
    android:startOffset="500"
    android:fromXDelta="100%" android:toXDelta="0%"
    android:fromYDelta="0%" android:toYDelta="0%"
    android:duration="700" />
</set>

这是slide_out_to_right:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
 android:shareInterpolator="false">
 <translate
    android:fromXDelta="0%" android:toXDelta="100%"
    android:fromYDelta="0%" android:toYDelta="0%"
    android:duration="700" />
</set>

【问题讨论】:

    标签: android


    【解决方案1】:

    不,您可以将translate 用于Activities,但不能用于fragment。您需要将objectAnimator 用于fragment

    看看这个问题的第一个答案,它的工作原理:

    Android FragmentTransaction Custom Animation (Unknown Animator Name: Translate)

    【讨论】:

    • 我在某处读到,使用 framelayout、translate 属性可以工作,并且该答案获得了 100 多个支持。
    • @HirakChhatbar 真的吗?抱歉,我对此一无所知..但您仍然遇到错误,我不知道如何使用框架布局修复它。
    • 谢谢你...我决定继续使用 objectAnimator (y)
    猜你喜欢
    • 2013-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-13
    • 2014-10-03
    • 2013-08-14
    • 2011-09-18
    • 1970-01-01
    相关资源
    最近更新 更多