gpt4 book ai didi

android - 未知的动画师姓名 : translate

转载 作者:太空狗 更新时间:2023-10-29 15:52:57 24 4
gpt4 key购买 nike

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

fragment 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>

fragment 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">

fragment A到 fragment 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>

这是动画 xml

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>

最佳答案

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

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

Android FragmentTransaction Custom Animation (Unknown Animator Name: Translate)

关于android - 未知的动画师姓名 : translate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26814360/

24 4 0
文章推荐: html - 在 Internet Explorer 中设置 `