事件攔截和分發demo

2021-07-10 16:24:47 字數 963 閱讀 5337

實現效果:頁面上豎直擺放3個listview,滑動左邊和右邊的listview正常滑動,滑動 中間listview 時 滑動整個螢幕。

這個效果實現 需要自定義乙個layout,然後對事件做處理即可。

布局引用:

**注釋:

package com.example.pinterestlistview;

import android.content.context;

import android.util.attributeset;

import android.view.motionevent;

import android.view.view;

import android.widget.linearlayout;

public class mylinearlayout extends linearlayout

@override

public boolean onintercepttouchevent(motionevent ev)

//將螢幕豎直平分為三個區域。第一和第三個區域可以自由滑動,第二個區域滑動上半部分 可以拖動整個螢幕,下半部分 滑動第二個區域。

Android中View的事件分發和攔截機制

部落格轉移到個人站點 歡迎來吐槽 1.關係到事件分發和攔截機制的三個方法 1.dispatchtouchevent motionevent event 方法 2.onintercepttouchevent motionevent event 方法 3.ontouchevent motionevent...

Android中View的事件分發和攔截機制

1.關係到事件分發和攔截機制的三個方法 1.dispatchtouchevent motionevent event 方法 2.onintercepttouchevent motionevent event 方法 3.ontouchevent motionevent event 方法2.dispat...

事件分發和事件傳遞

事件傳遞,是先分發,後攔截,從 父view 開始分發,dispatchtouchevent返回true的時候,由 父view 的ontouchevent處理 消費 返回false,交給 父view 的onintercepttouchevent法來決定是否要攔截這個事件,如果oninterceptto...