Android之RecyclerView或ListView的item上下翻转特效

一:翻转特效实现思路

  1. 定义两个View
  2. 点击第一个View向上翻转90°消失,第二个View显示
  3. 点击第二个View向上翻转90°消失,第一个View显示

二:效果图(没弄GIF,就是上下翻转的特效)

三:代码实现

1:创建一个翻转动画util

package com.example.fgkj.onepass.util;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.view.View;
import android.view.animation.OvershootInterpolator;

/**
 * 排行翻转动画util
 */
public class AnimUtilfz {
    public void FlipAnimatorXViewShow(final View oldView, final View newView, final long time) {

        ObjectAnimator animator1 = ObjectAnimator.ofFloat(oldView, "rotationX", 0, 90);
        final ObjectAnimator animator2 = ObjectAnimator.ofFloat(newView, "rotationX", -90, 0);
        animator2.setInterpolator(new OvershootInterpolator(2.0f));

        animator1.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                oldView.setVisibility(View.GONE);
                animator2.setDuration(time).start();
                newView.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        animator1.setDuration(time).start();
    }
}

2:如果是列表的情况,请先在Activity界面定义并先new一下,然后传给adapter

private AnimUtilfz animUtilfz;//翻转动画
 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //去掉状态栏
        if (Build.VERSION.SDK_INT >= 21) {
            View decorView = getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
            getWindow().setStatusBarColor(Color.parseColor("#00000000"));
        }
        setContentView(R.layout.ranking);
        instantiation();
        animUtilfz=new AnimUtilfz();
        requestData();
    }
 adapter = new RankingAdapter(animUtilfz,bean.list, Ranking.this);
                    recyclerview.setAdapter(adapter);

3:adapter接收及使用

private AnimUtilfz animUtilfz;
    private boolean isSelect = false;
 public RankingAdapter(AnimUtilfz animUtilfz, List<RankingBean.LIST> list, Context context) {
        this.list = list;
        this.context = context;
        this.animUtilfz = animUtilfz;
    }
 holder.relatie.setOnClickListener(new View.OnClickListener() {//第一个界面
            @Override
            public void onClick(View v) {
                isSelect = true;
                if (isSelect) {
                    animUtilfz.FlipAnimatorXViewShow(holder.relatie, holder.linearer, 800);
                }
            }
        });
        holder.linearer.setOnClickListener(new View.OnClickListener() {//第二个界面
            @Override
            public void onClick(View v) {
                isSelect = false;
                if (!isSelect) {
                    animUtilfz.FlipAnimatorXViewShow(holder.linearer, holder.relatie, 800);
                }
            }
        });

4:item的xml代码

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

    <!--第一个界面-->
    <RelativeLayout
        android:id="@+id/relatie"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:background="@drawable/hlistvback">

        <TextView
            android:id="@+id/textmc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:text="1"
            android:textColor="#333333"
            android:textSize="14dp" />

        <com.example.fgkj.onepass.util.CustomImageView
            android:id="@+id/imag1"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_marginLeft="10dp"
            android:layout_toRightOf="@+id/textmc"
            android:src="@mipmap/back" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_toRightOf="@+id/imag1"
            android:orientation="vertical">

            <TextView
                android:id="@+id/textzdm"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="I love 浪浪战队"
                android:textColor="#232323"
                android:textSize="12dp" />

            <TextView
                android:id="@+id/textjf"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:text="战队总积分:1200"
                android:textColor="#666666"
                android:textSize="9dp" />
        </LinearLayout>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_marginRight="20dp"
            android:src="@mipmap/jinpai1" />
    </RelativeLayout>

    <!--第二个界面-->
    <LinearLayout
        android:id="@+id/linearer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:background="@drawable/hlistvbackfs"
        android:orientation="vertical"
        android:visibility="gone">

        <!--胜场-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_weight="1"
                android:text="排位胜场:0"
                android:textColor="#ffffff"
                android:textSize="12dp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="对战胜场:0"
                android:textColor="#ffffff"
                android:textSize="12dp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="专业胜场:0"
                android:textColor="#ffffff"
                android:textSize="12dp" />

        </LinearLayout>
        <!--胜率-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_weight="1"
                android:text="排位胜率:0%"
                android:textColor="#ffffff"
                android:textSize="12dp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="对战胜率:0%"
                android:textColor="#ffffff"
                android:textSize="12dp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="专业胜率:0%"
                android:textColor="#ffffff"
                android:textSize="12dp" />

        </LinearLayout>
    </LinearLayout>
</LinearLayout>

-------就这么多,很简单,喜欢可以关注以免迷路------对了,喜欢记得点赞!

 

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

叶已初秋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值