【发布时间】:2018-12-28 14:26:34
【问题描述】:
我正在使用网格布局管理器使用 Recycler 视图。我想在按钮单击时滚动回收视图。(在按钮单击时,我正在传递位置,我的项目将突出显示)。所以我想在顶部显示突出显示的项目。可能是那个项目在不同的位置。
onViewCreated 我正在初始化的地方-----
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
recycleView = view.findViewById(R.id.recycler_vieww);
lLayout = new GridLayoutManager(context, 3);
recycleView.setLayoutManager(lLayout);
/* ItemOffsetDecoration itemDecoration = new ItemOffsetDecoration(context, R.dimen.item_offset);
recycleView.addItemDecoration(itemDecoration);*/
String channelId = "";
if (tvStatus != null && tvStatus.getData() != null && tvStatus.getData().getDetails().get(0).getChannelData() != null) {
if (tvStatus.getData().getDetails().get(0).getCurrentFeature().equalsIgnoreCase("channel")) {
//rcAdapter = new Televison_Adapter(context, chnlList,"43", shared, readDb);
if (tvStatus.getData().getDetails().get(0).getChannelData() != null) {
channelId = tvStatus.getData().getDetails().get(0).getChannelData().getChannelId();
}
}
}
rcAdapter = new Televison_Adapter(context, chnlList, channelId, shared, readDb,this);
rcAdapter.setOnChannelSelectListner(this);
rcAdapter.setOnSelectedListItemListner(this);
recycleView.setAdapter(rcAdapter);
rcAdapter.notifyDataSetChanged();
}
接口抽象方法 --- 我想从哪里滚动我的 recyclerView 和位置是从适配器类传递的。
@Override
public void getItemPosition(final int position) {
/*RecyclerView.SmoothScroller smoothScroller = new
LinearSmoothScroller(context) {
@Override protected int getVerticalSnapPreference() {
return LinearSmoothScroller.SNAP_TO_START;
}
};
smoothScroller.setTargetPosition(position);
lLayout.startSmoothScroll(smoothScroller);*/
recycleView.scrollTo(0,1000);
}
【问题讨论】:
-
你能发布你的代码吗?
-
@nik 你检查了吗
-
@Nilesh Rathod 解决方案没有帮助