将RecyclerView项目更改为高于其他所有项目 [英] change RecyclerView item to be above all others
本文介绍了将RecyclerView项目更改为高于其他所有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有卧式recyclerView,其中包含作为项目的图像. 如何检测RecycleView项何时位于屏幕中央,并强调它是这样的:
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 :
示例:
推荐答案
您可以将轮播逻辑与RecyclerView组合和SnapHelper兼容性类一起使用,如下所示:
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" />
然后将您的recyclerView附加到SnapHelper类:
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);
}
});
这篇关于将RecyclerView项目更改为高于其他所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文