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>-------就这么多,很简单,喜欢可以关注以免迷路------对了,喜欢记得点赞!
