我試圖實現一個RecylerView顯示在屏幕上1個CardView的時間和通過兩個左,右箭頭ImageButtons控制。我不想讓用戶自己滾動瀏覽RecyclerView。我如何禁用RecylerView的滾動和拖動功能?禁用Android的RecylerView滾動和一扔
這裏就是我初始化一個LinearLayoutManager
final LinearLayoutManager llm = new LinearLayoutManager(this);
llm.setOrientation(LinearLayoutManager.HORIZONTAL);
final RecyclerView recList = (RecyclerView) findViewById(R.id.card_holder);
recList.setHasFixedSize(true);
recList.setLayoutManager(llm);
視圖和這裏是我設置的左,右滾動按鈕
ImageButton rightClick = (ImageButton) findViewById(R.id.rightClick);
ImageButton leftClick = (ImageButton) findViewById(R.id.leftClick);
rightClick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int position = llm.findFirstVisibleItemPosition();
if(position != recList.getAdapter().getItemCount() - 1) {
markers[position + 1].showInfoWindow();
GMap.moveCamera(CameraUpdateFactory.newLatLngZoom(result.get(position + 1).latlng, 17.0f));
recList.smoothScrollToPosition(llm.findFirstVisibleItemPosition() + 1);
}
}
});
leftClick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int position = llm.findFirstVisibleItemPosition();
if(position != 0) {
GMap.moveCamera(CameraUpdateFactory.newLatLngZoom(result.get(llm.findFirstVisibleItemPosition() - 1).latlng, 17.0f));
recList.smoothScrollToPosition(llm.findFirstVisibleItemPosition() - 1);
}
}
});