1. 概述
在開發(fā)過程中,有時(shí)候會(huì)因?yàn)槟撤N原因需要 禁止ListView或者RecyclerView的滑動(dòng)事件,比如顯示多類型布局時(shí),如果其中需要加載 lv或者rv 的列表,這個(gè)時(shí)候,為了頁面美觀程度,其實(shí)是可以禁止 lv或者rv 的滑動(dòng)事件的,直接讓整體的多種類型布局滑動(dòng)即可,不要讓單個(gè) lv或者rv 滑動(dòng)。
2. 實(shí)現(xiàn)方式
1>:ListView禁止滑動(dòng)實(shí)現(xiàn):
攔截 listview的 onTouch()事件即可,即就是讓 Action_Move返回true即可;
lv.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
return true;
default:
break;
}
return true;
}
});`
2>:RecyclerView禁止滑動(dòng)實(shí)現(xiàn):
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
//設(shè)置布局管理器
recyclerView.setLayoutManager(new LinearLayoutManager(this));
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(MainActivity.this,
LinearLayoutManager.VERTICAL, false) {
@Override
public boolean canScrollVertically() {
return false;
}
};
recyclerView.setLayoutManager(linearLayoutManager);
adapter = new RecyclerAdapter(this,picList,channelList,girlList,normalList);
recyclerView.setAdapter(adapter);