1
私は前のカードスタックを重ねて、下から上にスワイプしてカードを実装したい。誰かがカスタムレイアウトマネージャでRecyclerViewを使ってこれを実装している。十分なコードがない。StackLayoutManagerをアンドロイドで実装する方法Vertical RecyclerView
Recyclerviewを使用してこれを行う方法。
recyclerView.setLayoutManager(new StackLayoutManager(this));
をそして最後にスワイプを処理するためのItemTouchHelperを追加します:あなたのRecyclerViewでそれを使用するよりも
public class StackLayoutManager extends LinearLayoutManager {
public StackLayoutManager(Context context) {
super(context);
setStackFromEnd(true);
}
@Override
public RecyclerView.LayoutParams generateDefaultLayoutParams() {
return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}
@Override
public boolean canScrollHorizontally() {
return false;
}
@Override
public boolean canScrollVertically() {
return false;
}
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
super.onLayoutChildren(recycler, state);
updatePosition();
}
private void updatePosition() {
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View view = getChildAt(i);
ViewCompat.setTranslationY(view, -view.getTop());
}
}
}
を:
おかげで... –