Horizontally center first item of RecyclerView

前端 未结 4 1294
孤城傲影
孤城傲影 2020-12-14 23:12

I want to use a RecyclerView to emulate the behavior of a MultiViewPager, in particular I\'d like to have the selected item at the center of the sc

4条回答
  •  情话喂你
    2020-12-14 23:46

    You can implement this with an RecyclerView.ItemDecoration in getItemOffsets(), to offset the first and last item appropriately.

    Retrieve any offsets for the given item. Each field of outRect specifies the number of pixels that the item view should be inset by, similar to padding or margin. The default implementation sets the bounds of outRect to 0 and returns.

    If you need to access Adapter for additional data, you can call getChildAdapterPosition(View) to get the adapter position of the View.

    You might need to use the messured size of the item and the RecyclerView as well. But these information is available to be used anyhow.

提交回复
热议问题