开发者

How do I keep a touch event keep its focus on the widget it was started in?

开发者 https://www.devze.com 2023-02-24 05:18 出处:网络
Let\'s say I have a ListView, and one row in it is a custom View of mine. The开发者_开发百科 user touches inside the custom view -> custom View gets to handle this touch event. User continues this tou

Let's say I have a ListView, and one row in it is a custom View of mine. The开发者_开发百科 user touches inside the custom view -> custom View gets to handle this touch event. User continues this touch sequence inside the are of the custom View -> custom View gets to handle those events too.

Problem: When the user drags his/her finger outside the area of the custom View (the drag started inside), the custom View losts the touch events. But I need those events too, how can I achieve this?

I know that this can be done: if you put a Gallery containing a bunch of images inside a LisView, and I start to drag the Gallery left-right, and drag my finger outside the area of the Gallery while doing so (moving up/downwards too much), I still control the Gallery scrolling, not the ListView.

I hope that I was clear enough, does anyone have some tips on this problem?


According to this post by Dianne Hackborn, if you return true to a down event in a view's onTouchEvent(), following events are sent automatically to that view.


To get all following events I also had to call view.getParent().requestDisallowInterceptTouchEvent(true) in my onTouch Listener.

0

精彩评论

暂无评论...
验证码 换一张
取 消