RecyclerView的進場動畫、點擊動畫

本文連接:https://blog.csdn.net/cpcpcp123/article/details/84567010
下面圖片即爲本次的運行效果:java

 

1.進場動畫是在viewholder中的onViewAttachedToWindow()中添加動畫便可,動畫的代碼:
private ScaleInAnimation mSelectAnimation = new ScaleInAnimation();
 
@Override
    public void onViewAttachedToWindow(DiffVH holder) {
        super.onViewAttachedToWindow(holder);
        addAnimation(holder);
    }
 
private void addAnimation(DiffVH holder) {
        for (Animator anim : mSelectAnimation.getAnimators(holder.itemView)) {
            anim.setDuration(300).start();
            anim.setInterpolator(new LinearInterpolator());
        }
    }
ScaleInAnimation.java:android

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.view.View;
 
public class ScaleInAnimation{
    private static final float DEFAULT_SCALE_FROM = .5f;
    private final float mFrom;
 
    public ScaleInAnimation() {
        this(DEFAULT_SCALE_FROM);
    }
 
    public ScaleInAnimation(float from) {
        mFrom = from;
    }
 
    public Animator[] getAnimators(View view) {
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", mFrom, 1f);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", mFrom, 1f);
        return new ObjectAnimator[]{scaleX, scaleY};
    }
}
2.每一個item的點擊效果是一個自定義view,具體看BamLinearLayout.java
使用的話直接在xml中引用便可:git

<com.example.diffut.BamLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="120dp"
    android:layout_marginBottom="1dp"
    android:padding="5dp"
    android:background="@mipmap/background"
    android:orientation="vertical">
 
    <TextView
        android:id="@+id/tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="22sp"
        android:textStyle="bold"
        tools:text="第一個" />
 
    <TextView
        android:id="@+id/tv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="24sp"
        android:textStyle="bold"
        tools:text="個人存在只爲了證實定向刷新中的定向刷新" />
 
    <com.example.diffut.TextSwitchView
        android:id="@+id/switchView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
 
</com.example.diffut.BamLinearLayout>
完整的項目地址:github

https://github.com/buder-cp/base_component_learn/tree/master/diffut
————————————————
版權聲明:本文爲CSDN博主「buder得兒得兒以得兒以得兒得兒」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處連接及本聲明。
原文連接:https://blog.csdn.net/cpcpcp123/article/details/84567010ide

相關文章
相關標籤/搜索