Android 安卓:如何向上滑动碎片?

Android 安卓:如何向上滑动碎片?,android,android-fragments,android-animation,Android,Android Fragments,Android Animation,我试图添加动画的一个片段出现在按钮点击,从底部 片段布局 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layo

我试图添加动画的一个片段出现在按钮点击,从底部

片段布局

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:background="@color/wallet_holo_blue_light"
        android:layout_gravity="center"
        android:text="This is a fragmentt layout"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />

</RelativeLayout>
演示如何上下滑动,我只需将片段设置为向上动画。因此,我的问题是setcustomanimation()函数的第二个参数


在提交之前,我尝试使用
fragmentTransaction.setCustomAnimations()
,但没有帮助

它确实出现在底部,但没有过渡效果。 任何指导都是有用的。
谢谢

您应该在添加之前设置自定义动画,仅此而已

另外,您的代码应该有问题,因为您应该使用片段的支持库(v4)而不是应用程序,并且在使用片段时调用getSupportFragmentManager并修复代码的所有部分,而您不使用支持库

如果不想更改此设置,可以将此代码用于幻灯片动画:

<?xml version="1.0" encoding="utf-8"?>
<objectAnimator
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:propertyName="translationY"
    android:valueType="floatType"
    android:valueFrom="1280"
    android:valueTo="0"
    android:duration="@android:integer/config_mediumAnimTime"/>


setcustomanimation的第二个参数是否可能重复?setCustomAnimation(R.id.slideup,?)fragmentTransaction.setCustomAnimations(R.animator.slide_up,0);如果使用支持库,请向上滑动R.anim.slide\u。请参阅我编辑的代码。没有动画。用了你的滑梯。碎片刚刚出现。没有滑动效果。正如我所说,您应该在添加之前设置CustomAnimation,如果它对您不起作用,则将xml文件更改为我添加的代码,或者按照我在回答中所说的更改进行操作。是的,这很有效。我的错。我是在添加之后添加的。
public void onClick(View view) {

           if(view == button ){

        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        FragmentOnMap hello = new FragmentOnMap();

        fragmentTransaction.add(R.id.fragment_container, hello, "HELLO");
        fragmentTransaction.setCustomAnimations(R.animator.slide_up,0);
        fragmentTransaction.commit();
    }


}
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:propertyName="translationY"
    android:valueType="floatType"
    android:valueFrom="1280"
    android:valueTo="0"
    android:duration="@android:integer/config_mediumAnimTime"/>