小编Ser*_*g P的帖子

SnapHelper项目位置


我正在使用垂直RecyclerView列出我的项目并SnapHelper捕捉中心项目.这个想法是随机选择,所以用户刷屏或摇动设备,它滚动到随机位置.
项目数量是20,但是我使用Integer.MAX_VALUE的元素数量RecyclerView和初始化RecyclerView的位置Integer.MAX_VALUE / 2来创建某种无穷无尽的列表.
要在设备震动时滚动到随机位置,我需要知道当前捕捉的项目位置.
有什么办法吗?

这是我的片段代码:

public class PlaceListFragment extends Fragment {

private static final String TAG = "PlaceListFragment";
public static final String ARG_KEY1 = "key1";
private ArrayList<PlaceItem> places;

private RecyclerView recyclerView;

private SensorManager sensorManager;
private float accelValue;
private float accelLast;
private float shake;

SnapHelper snapHelper;

Vibrator vibe;


    public static PlaceListFragment newInstance() {

        Bundle args = new Bundle();

        PlaceListFragment fragment = new PlaceListFragment();
        fragment.setArguments(args);
        return fragment;
    }

    public static …
Run Code Online (Sandbox Code Playgroud)

java android android-recyclerview

10
推荐指数
1
解决办法
7319
查看次数

标签 统计

android ×1

android-recyclerview ×1

java ×1