Java Code Examples for androidx.recyclerview.widget.LinearSnapHelper#attachToRecyclerView()

The following examples show how to use androidx.recyclerview.widget.LinearSnapHelper#attachToRecyclerView() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LinearSnapMAXActivity.java    From DevUtils with Apache License 2.0 6 votes vote down vote up
@Override
    public void initValues() {
        super.initValues();

        List<ItemBean> lists = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            lists.add(ItemBean.newItemBean());
        }

        // 初始化布局管理器、适配器
        linearSnapAdapter = new LinearSnapMAXAdapter(this, lists);
        vid_bvr_recy.setLayoutManager(new LinearLayoutManager(this, RecyclerView.HORIZONTAL, false));
//        vid_bvr_recy.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false));
        vid_bvr_recy.setAdapter(linearSnapAdapter);

        LinearSnapHelper helper = new LinearSnapHelper();
        helper.attachToRecyclerView(vid_bvr_recy);


        int size = lists.size();
        // 滑动到中间 ( 无滑动过程 )
        ((LinearLayoutManager) vid_bvr_recy.getLayoutManager()).scrollToPositionWithOffset(size * 100 - 1, 10);
        // 复位到中间
        ListViewUtils.smoothScrollToPosition(vid_bvr_recy, size * 100 + 1);
    }
 
Example 2
Source File: LinearSnapActivity.java    From DevUtils with Apache License 2.0 6 votes vote down vote up
@Override
    public void initValues() {
        super.initValues();

        List<ItemBean> lists = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            lists.add(ItemBean.newItemBean());
        }

        // 初始化布局管理器、适配器
        linearSnapAdapter = new LinearSnapAdapter(lists);
        vid_bvr_recy.setLayoutManager(new LinearLayoutManager(this, RecyclerView.HORIZONTAL, false));
//        vid_bvr_recy.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false));
        vid_bvr_recy.setAdapter(linearSnapAdapter);

        LinearSnapHelper helper = new LinearSnapHelper();
        helper.attachToRecyclerView(vid_bvr_recy);
    }
 
Example 3
Source File: CarouselDecorator.java    From Hentoid with Apache License 2.0 5 votes vote down vote up
public void decorate(RecyclerView recyclerView) {
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(adapter);
    recyclerView.addOnScrollListener(new CarouselOnScrollListener());

    LinearSnapHelper snapHelper = new LinearSnapHelper();
    snapHelper.attachToRecyclerView(recyclerView);
}