我在PagerSnapHelper中使用了recyclerview来一页一页地滚动。这里的视图高度和宽度是match_parent。问题是当我在recyclerview中滚动页面时,该位置在项目位置0处看起来像0和1,然后在我滚动页面时它在项目位置1处显示位置1和2。看起来很完美,但是由于这个职位之王,我的视图点击事件不起作用。我猛冲时一次只想要一个位置。例如,第一次加载页面时,它显示位置0,然后当我滚动页面时,它应该显示1,再次滚动时,该位置应该显示2,依此类推。我注意到PagerSnapHelper的另一件事是,当我从右向左反向滚动时,位置会随机显示,而不是像3,2,1这样的流显示?
下面是在活动中设置的recyclerview。
RecyclerView.LayoutManager mLayoutManager = new
LinearLayoutManager(ReportActivity.this, LinearLayoutManager.HORIZONTAL,
false);
PagerSnapHelper pagerSnapHelper = new SnapHelperOneByOne();
recyclerViewreport.setLayoutManager(mLayoutManager);
pagerSnapHelper.attachToRecyclerView(recyclerViewreport);
recyclerviewReportAdapter = new RecyclerviewReportAdapter(reportList,
ReportActivity.this, recyclerViewreport, linearSnapHelper,
onTouchListener, isEnabledPagePadding);
recyclerViewreport.setAdapter(recyclerviewReportAdapter);
recyclerviewReportAdapter.notifyDataSetChanged();
///这是适配器类中relativeLayout的单击事件。
holder.relativeLayoutForehead.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View view) {
ivFace.setForheadZoom();
if (!isVisible) {
holder.relativeLayoutAcneDesc.setVisibility(View.VISIBLE);
holder.ivTriangleForhead.setVisibility(View.VISIBLE);
holder.ivTriangleCheek.setVisibility(View.GONE);
holder.ivTriangleChin.setVisibility(View.GONE);
holder.ivTriangleNose.setVisibility(View.GONE);
holder.tvAcneInfo.setText(forehead.getText());
isVisible = true;
} else {
holder.relativeLayoutAcneDesc.setVisibility(View.GONE);
holder.ivTriangleForhead.setVisibility(View.GONE);
holder.ivTriangleCheek.setVisibility(View.GONE);
holder.ivTriangleChin.setVisibility(View.GONE);
holder.ivTriangleNose.setVisibility(View.GONE);
isVisible = false;
}
}
});