问题
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 :
Example :

回答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:
LinearSnapHelper snapHelper = new LinearSnapHelper();
snapHelper.attachToRecyclerView(recyclerView);
And provide the logic for currently selected centered item:
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
float pos = (float) recyclerView.computeHorizontalScrollOffset() / (float) itemHeight;
int itemPos = (int) Math.floor(pos);
}
super.onScrollStateChanged(recyclerView, newState);
}
});
来源:https://stackoverflow.com/questions/50760805/change-recyclerview-item-to-be-above-all-others