2
スクロールリサイクルで問題が発生します。 はここに私のLinearlayoutManagerです:ここ水平スクロールsmoothScrollToPositionのリサイクルビューは動作しません
public class LayoutManagerCustom extends LinearLayoutManager {
private static final float MILLISECONDS_PER_INCH = 50f;
private Context mContext;
public LayoutManagerCustom(Context context) {
super(context);
mContext = context;
}
public LayoutManagerCustom(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
this.mContext = context;
}
@Override
public void smoothScrollToPosition(RecyclerView recyclerView,
final RecyclerView.State state, final int position) {
LinearSmoothScroller smoothScroller =
new LinearSmoothScroller(mContext) {
//This controls the direction in which smoothScroll looks
//for your view
@Override
public PointF computeScrollVectorForPosition
(int targetPosition) {
return LayoutManagerCustom.this
.computeScrollVectorForPosition(targetPosition);
}
//This returns the milliseconds it takes to
//scroll one pixel.
@Override
protected float calculateSpeedPerPixel
(DisplayMetrics displayMetrics) {
return MILLISECONDS_PER_INCH/displayMetrics.densityDpi;
}
};
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);
}
@Override
public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) {
return super.scrollHorizontallyBy(dx, recycler, state);
}
}
としてRecycleViewを作成するための私のコードです:デバッグモードで
layoutManager = new LayoutManagerCustom(getContext(), LinearLayoutManager.HORIZONTAL,false);
recyclerViewItem.setLayoutManager(layoutManager);
recyclerViewItem.setAdapter(recycleViewItemAdapter);
params.smoothScrollToPosition(recyclerViewItem, new RecyclerView.State(),Constant.NUM_DATE/2);
、私が見た
computeScrollVectorForPosition
は、VERTICALでlayoutManagerを作成する場合に呼び出されますが、HORIZONTALでは呼び出されません。読書のための Customizing SmoothScroller for the RecyclerView
ありがとう:ここ
そして、これについての例です。