How to make a page indicator for horizontal recyclerview

前端 未结 10 1139
说谎
说谎 2021-01-30 05:32

Any idea how to create a page indicator for recyclerview list ?

10条回答
  •  说谎
    说谎 (楼主)
    2021-01-30 06:05

    there is actually a very good library for this purpose. just add this to your gradle dependencies

    implementation "ru.tinkoff.scrollingpagerindicator:scrollingpagerindicator:1.0.6"
    

    then add the layout

    
    
    
    

    then add the indicator to your recyclerview like this

    RecyclerView recyclerView = findViewById(R.id.recycler);
    LayoutManager layoutManager = new LinearLayoutManager(this, 
    LinearLayoutManager.HORIZONTAL, false);
    recyclerView.setLayoutManager(layoutManager);
    DemoRecyclerViewAdapter recyclerAdapter = new DemoRecyclerViewAdapter();
    recyclerView.setAdapter(recyclerAdapter);
    
    ScrollingPagerIndicator recyclerIndicator = findViewById(R.id.indicator);
    recyclerIndicator.attachToRecyclerView(recyclerView);
    

提交回复
热议问题