【发布时间】:2016-10-23 10:29:31
【问题描述】:
我正在尝试将动画添加到按钮单击时出现的片段,从底部开始。
片段布局
<?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>
向上滑动.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_mediumAnimTime">
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_mediumAnimTime"
android:fromYDelta="50.0%p"
android:interpolator="@android:anim/decelerate_interpolator"
android:toYDelta="30" />
</set>
在这里调用它:
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();
}
}
Android Fragments and animation 展示了如何上下滑动,我只是动画的片段。因此我的问题是 setcustomanimation() 函数的第二个参数
我在提交之前尝试使用fragmentTransaction.setCustomAnimations(),但没有帮助。
它确实出现在底部,但没有过渡效果。 任何指导都会很有用。 谢谢
【问题讨论】:
标签: android android-fragments android-animation