您的位置:首页 > 移动开发 > Objective-C

fragment设置关于translationY属性的objectAnimator属性动画

2017-03-09 09:36 381 查看
在给fragment设置关于translationY属性的objectAnimator属性动画时,如果valueFrom的值大于等于fragment的高度时(下面代码中的第一个动画),fragment的这个动画不能在activity上显示出来,当valueFrom的值小于fragment的高度时,fragment的这个动画就能在activity上正常显示。请问为何会出现这种情况。fragment设置动画的代码:

@Override
public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) {
Animator anim;
if (enter) {
anim = ObjectAnimator.ofFloat(mRootView, "translationY", mRootView.getHeight(), 0).setDuration(2000);
} else {
anim = ObjectAnimator.ofFloat(mRootView, "translationY", 0, mRootView.getHeight()-1).setDuration(2000);
}

return anim;
}


fragment的mRootView的layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:background="@drawable/bg_white"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_marginLeft="30dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:layout_marginRight="40dp"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/icon_navigation"/>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="@string/app_name"
android:id="@+id/location_txv"
android:gravity="center_vertical"
android:textSize="16sp"/>
</LinearLayout>

转自:https://segmentfault.com/q/1010000005881329
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: