我正在尝试在Android中实现一个自定义线性布局管理器。用于获得水平自动滑动的RecolyerView。但是当我试图将自定义类调用到主java类中时,我会遇到一些问题。
下面列出了我的代码所面临的问题。
public CustomLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
}
public CustomLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
customLinearLayoutManager.smoothScrollToPosition();
public class CustomLinearLayoutManager extends LinearLayoutManager {
public CustomLinearLayoutManager (Context context) {
super(context);
}
public CustomLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
}
public CustomLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
final LinearSmoothScroller linearSmoothScroller =
new LinearSmoothScroller(recyclerView.getContext()) {
private static final float MILLISECONDS_PER_INCH = 200f;
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
return CustomLinearLayoutManager.this
.computeScrollVectorForPosition(targetPosition);
}
@Override
protected float calculateSpeedPerPixel
(DisplayMetrics displayMetrics) {
return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
}
};
linearSmoothScroller.setTargetPosition(position);
startSmoothScroll(linearSmoothScroller);
}
}
CustomLinearLayoutManager customLinearLayoutManager = new CustomLinearLayoutManager(getContext());
customLinearLayoutManager.smoothScrollToPosition();
recyclerViewHeaderSlider = view.findViewById(R.id.bannerSlider);
SnapHelper snapHelper = new PagerSnapHelper();
snapHelper.attachToRecyclerView(recyclerViewHeaderSlider);
recyclerViewHeaderSlider.setHasFixedSize(true);
recyclerViewHeaderSlider.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
headerSliderAdapter.setOnClick(this);
recyclerViewHeaderSlider.setAdapter(headerSliderAdapter);
请告诉上述错误的解决方法。另外,请精确的代码,以实现水平自动滑动回收视图。使用我已经提到的自定义线性布局管理器。
为什么不使用普通线性布局管理器并将方向设置为水平
我正在制作一个应用程序,其中我使用和类来制作一个可滚动的水平卡片堆栈。我已经成功地实现了,但我的问题是刷卡向右的方向,我想刷卡向左的方向。 我对SO做了一些研究,发现了1和2 更新:我仍然在努力,几乎没有发现很多,因为它仍然很难改变滚动的方向在回收,所以任何人仍然想帮助我,是欢迎的。 我还发现方法传递滚动位置和direcion可能我错了,但beow code可能是解决方案 我的主要班级 这是我的s
我想创建一个应用程序的模式介绍:就像当你第一次下载一个应用程序,看到smth一样的教程,你可以跳过它 问题是跳过按钮是可见的,箭头符号是导入的组件,但数据是不可见的,模拟器崩溃。我杀了bundler,没有改变。当我评论时,mapping it app可以工作,但Flatlist不行。
问题内容: 我有一个,当行太多时,会出现滚动条,但是当行太长时,该行会分成两行,而不是出现水平滚动条,如何使水平条出现而不是分成两行,我的添加如下: 问题答案: 正如我们自己的Rob Camick 在这里介绍的那样,您可以尝试使用类似… 这将停止行/自动换行
本文向大家介绍Android使用HorizontalScrollView实现水平滚动,包括了Android使用HorizontalScrollView实现水平滚动的使用技巧和注意事项,需要的朋友参考一下 HorizontalScrollView 和 ScrollView 都是由 FrameLayout 派生出来的。它们就是一个用于为普通组件添加滚动条的组件。且 HorizontalScrollVi
问题内容: 我正在尝试创建一系列只能水平滚动的照片。 它应该看起来像这样的 但是,只有通过指定包含照片的的宽度,才能实现上述目的(因此它们不会“自动换行”)。如果我不放宽- 看起来像这样; 使用CSS可以防止固定宽度的图像发生变化,该怎么办。 谢谢 问题答案: 您可以使用与。这样写: