我具有水平recyclerview
其可以在一个时间显示1.5的物品,是指在屏幕上1名完整的项目,第二项目的局部视图。
我想改变在当前位置的背景颜色或主要项目的设定字母或项目。
如果我使用下面的代码它为第二个项目阿尔法。
if(position == 1){
holder.itemView.setAlpha(0.5f);
}else{
holder.itemView.setAlpha(1.0f);
}
但我想知道一个动态的方式来设置阿尔法0.5f
为项目的休息,1.0f
当前索引。
任何可见的子取决于LayoutManager的。如果你正在使用LinearLayoutManager或GridLayoutManager,您可以使用这些功能
int findFirstVisibleItemPosition();
int findFirstCompletelyVisibleItemPosition();
int findLastVisibleItemPosition();
int findLastCompletelyVisibleItemPosition();
例如:
GridLayoutManager的layoutManager =((GridLayoutManager)mRecyclerView.getLayoutManager()); INT firstVisiblePosition = layoutManager.findFirstVisibleItemPosition();
你可以使用这些功能..