卡片联动效果

This commit is contained in:
zhangyuanzhen
2020-03-12 19:29:25 +08:00
parent 89a9f33e4b
commit 041c09af8e
4 changed files with 73 additions and 198 deletions

View File

@@ -5,6 +5,7 @@ import android.graphics.Point;
import android.graphics.PointF;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.DisplayMetrics;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
@@ -14,6 +15,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.accessibility.AccessibilityEventCompat;
import androidx.core.view.accessibility.AccessibilityRecordCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.LinearSmoothScroller;
import androidx.recyclerview.widget.RecyclerView;
import com.yarolegovich.discretescrollview.transform.DiscreteScrollItemTransformer;
@@ -23,7 +25,7 @@ import java.util.Locale;
/**
* Created by yarolegovich on 17.02.2017.
*/
class DiscreteScrollLayoutManager extends RecyclerView.LayoutManager {
class DiscreteScrollLayoutManager extends LinearLayoutManager {
static final int NO_POSITION = -1;
@@ -79,6 +81,7 @@ class DiscreteScrollLayoutManager extends RecyclerView.LayoutManager {
@NonNull Context c,
@NonNull ScrollStateListener scrollStateListener,
@NonNull DSVOrientation orientation) {
super(c);
this.context = c;
this.timeForItemSettle = DEFAULT_TIME_FOR_ITEM_SETTLE;
this.pendingPosition = NO_POSITION;
@@ -355,18 +358,39 @@ class DiscreteScrollLayoutManager extends RecyclerView.LayoutManager {
recyclerViewProxy.requestLayout();
}
//@Override
//public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
// if (currentPosition == position || pendingPosition != NO_POSITION) {
// return;
// }
// checkTargetPosition(state, position);
// if (currentPosition == NO_POSITION) {
// //Layout not happened yet
// currentPosition = position;
// } else {
// startSmoothPendingScroll(position);
// }
//}
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
if (currentPosition == position || pendingPosition != NO_POSITION) {
return;
}
checkTargetPosition(state, position);
if (currentPosition == NO_POSITION) {
//Layout not happened yet
currentPosition = position;
} else {
startSmoothPendingScroll(position);
}
LinearSmoothScroller smoothScroller =
new LinearSmoothScroller(recyclerView.getContext()) {
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
// 返回滑过1px时经历的时间(ms)。
return 150f / displayMetrics.densityDpi;
}
@Override
public int calculateDtToFit(int viewStart, int viewEnd, int boxStart, int boxEnd, int snapPreference) {
return boxStart - viewStart;
}
};
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);
}
@Override
@@ -512,6 +536,9 @@ class DiscreteScrollLayoutManager extends RecyclerView.LayoutManager {
startSmoothPendingScroll();
}
@Override
public boolean isAutoMeasureEnabled() {
return true;