問題:LinearSmoothScroller,有時不會滑動-2020-5-25
場景:
bottom_list.setVisibility(View.VISIBLE);//一開始列表是隱藏,這是用於列表顯示
RecyclerView recyclerView = (RecyclerView) mapLayout.findViewById(R.id.recycler_view);
LinearLayoutManager linelarLayoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(linelarLayoutManager);
map_bottom_Adapter adapter = new map_bottom_Adapter(getActivity(), tips,mMapView);
recyclerView.setAdapter(adapter);
//平移
LinearSmoothScroller s1 = new map_bottom_Adapter.TopSmoothScroller(getActivity());
s1.setTargetPosition(5);
linelarLayoutManager.startSmoothScroll(s1);
一進頁面列表是隱藏但是渲染好的,通過點擊顯示列表,進行移到某個位置,但是不會滑動
解決:
bottom_list.setVisibility(View.VISIBLE);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
//要執行的操作
RecyclerView recyclerView = (RecyclerView) mapLayout.findViewById(R.id.recycler_view);
LinearLayoutManager linelarLayoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(linelarLayoutManager);
map_bottom_Adapter adapter = new map_bottom_Adapter(getActivity(), tips,mMapView);
recyclerView.setAdapter(adapter);
LinearSmoothScroller s1 = new map_bottom_Adapter.TopSmoothScroller(getActivity());
s1.setTargetPosition(5);
linelarLayoutManager.startSmoothScroll(s1);
}
}, 300);//0.3秒後執行Runnable中的run方法
讓滑動延時一段時間後再進行,我設置300,你可以根據自己改