Fragment底部弹出与下滑消失 动画

首先要在res/anim文件夹下创建两个xml文件(一个弹出动画 一个下滑消失动画)

弹出动画:

<?xml version="1.0" encoding="utf-8"?>

<translate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromYDelta="100%p"
    android:fillAfter="true"
    android:toYDelta="0%p"/>
<!--    duration:属性为动画持续时间,时间以毫秒为单位。-->
<!--    fromXDelta:属性为动画起始时,X坐标上的位置。-->
<!--    fromYDelta:属性为动画起始时,Y坐标上的位置。-->
<!--    toXDelta:属性为动画结束时,X坐标上的位置。-->
<!--    toYDelta:属性为动画结束时,Y坐标上的位置。-->

下滑消失:

<?xml version="1.0" encoding="utf-8"?>

<translate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromYDelta="0%p"
    android:toYDelta="100%p"/>
<!--    duration:属性为动画持续时间,时间以毫秒为单位。-->
<!--    fromXDelta:属性为动画起始时,X坐标上的位置。-->
<!--    fromYDelta:属性为动画起始时,Y坐标上的位置。-->
<!--    toXDelta:属性为动画结束时,X坐标上的位置。-->
<!--    toYDelta:属性为动画结束时,Y坐标上的位置。-->

以评论按钮为例子
在add前使用setCustomAnimations(进入时动画,退出时动画)
注意 该处参数是根据setCustomAnimations方法后的方法(如add,hide等)来进行选择执行哪一个参数的动画 因此 在评论窗返回的时候也要再设置一个退回动画 (如果不设置的话 哪怕设置点击事件里hide该fragment 评论页面仍然会存在不消失 暂时推测为动画的原因
setCustomAnimations(R.anim.comment_up_animation, R.anim.comment_down_animation) .add()
评论的点击事件中:

     @Override
            public void setOnCommentClickListener(ArrayList<CommentData> commentDataArrayList) {
                Fragment feedCommentFragment = getFragmentManager().findFragmentByTag("feedCommentFragment");
                if (feedCommentFragment == null) {
                    feedCommentFragment = FeedCommentFragment.newInstance(commentDataArrayList);
                    getActivity().getSupportFragmentManager().beginTransaction()
                            .setCustomAnimations(R.anim.comment_up_animation, R.anim.comment_down_animation)
                            .add(R.id.linear_comment, feedCommentFragment, "feedCommentFragment")
                            .addToBackStack(null).commitAllowingStateLoss();

                } else {
                    getActivity().getSupportFragmentManager().beginTransaction()
                            .setCustomAnimations(R.anim.comment_up_animation, R.anim.comment_down_animation)
                            .show(feedCommentFragment)
                            .addToBackStack(null).commitAllowingStateLoss();

                }
            }

返回的点击事件:

   @Override
   public void onClick(View v) {
     Fragment feedCommentFragment = getFragmentManager().findFragmentByTag("feedCommentFragment");
                getActivity().getSupportFragmentManager().beginTransaction()
                       .setCustomAnimations(R.anim.comment_down_animation,R.anim.comment_down_animation)
                       .hide(feedCommentFragment).commitAllowingStateLoss();

            }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值