Skip to content Skip to sidebar Skip to footer

Change Recyclerview Item To Be Above All Others

I have horizontal recyclerView that contains images as items. How can I detect when a RecycleView item is in the center of the screen and emphasize it to be something like this : E

Solution 1:

You could use the carousel logic with RecyclerView combination and SnapHelper compatibility class like this:

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fadingEdge="horizontal"
    android:overScrollMode="never"
    android:requiresFadingEdge="horizontal" />

Then attach your recyclerView with SnapHelper class:

LinearSnapHelpersnapHelper=newLinearSnapHelper();
snapHelper.attachToRecyclerView(recyclerView);

And provide the logic for currently selected centered item:

recyclerView.addOnScrollListener(newRecyclerView.OnScrollListener() {
    @OverridepublicvoidonScrollStateChanged(RecyclerView recyclerView, int newState) {
        if (newState == RecyclerView.SCROLL_STATE_IDLE) {
            floatpos= (float) recyclerView.computeHorizontalScrollOffset() / (float) itemHeight;
            intitemPos= (int) Math.floor(pos);
        }
        super.onScrollStateChanged(recyclerView, newState);
    }
});

Post a Comment for "Change Recyclerview Item To Be Above All Others"