[英]Translate(Slide in) animation not working android
In my app what i want is that on button click i wanna slide in a fragment and on again on click slide out the fragment.My code for sliding the fragment down is working but the sliding in transition is not working.. 在我的应用程序中,我想要的是在按钮上单击我要滑入片段,然后再次单击以滑出片段。我将片段向下滑动的代码有效,但过渡过渡不起作用..
Slide Up 向上滑动
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<objectAnimator
android:interpolator="@android:anim/linear_interpolator"
android:propertyName="getXFraction"
android:valueType="floatType"
android:valueFrom="0"
android:valueTo="1000"
android:duration="@android:integer/config_mediumAnimTime"/>
<objectAnimator
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:propertyName="alpha"
android:valueType="floatType"
android:valueFrom="0"
android:valueTo="1.0"
android:duration="@android:integer/config_mediumAnimTime"/>
</set>
Slide down 滑下
<?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="0"
android:valueTo="1280"
android:duration="1000"/>
Code 码
private void toggleList() {
Fragment f = getFragmentManager()
.findFragmentByTag(LIST_FRAGMENT_TAG);
if (f != null) {
getFragmentManager().popBackStack();
} else {
getFragmentManager().beginTransaction()
.setCustomAnimations(R.animator.slide_up,
R.animator.slide_down,
R.animator.slide_up,
R.animator.slide_down)
.add(R.id.frag_container, new frag(),
LIST_FRAGMENT_TAG
).addToBackStack(null).commit();
}
}
As you're using xFraction
(in my code, it's just xFraction
not getXFraction
), I believe you only need to animate between 0 and 1 (the unit is screen width). 当您使用xFraction
(在我的代码中,它只是xFraction
而不是getXFraction
)时,我相信您只需要在0到1之间设置动画(单位是屏幕宽度)。 Setting the latter to 100 results in moving object 100x the screen width. 将后者设置为100会导致移动对象是屏幕宽度的100倍。 Slide down
is working (but only for a specific screen size) because in that case you are using yTranslate
, for which the units are pixels. Slide down
有效(但仅适用于特定的屏幕尺寸),因为在这种情况下,您使用的是yTranslate
,其单位是像素。 In that case, you'd be better to use yFraction
set from 0 to 1. As others have commented, if all else fails, test slide in
as a solo animation before adding it to a set. 在这种情况下,最好使用yFraction
set(从0到1)。正如其他人所评论的那样,如果其他所有方法均失败,请在将slide in
添加到集合之前将其作为单独动画进行测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.