Today in the project process encountered in the ListView item needs to use the ListView to show the processed content, and then encountered a very headache problem, as item of the ListView can not slide, and display is not normal, just display a few sub item. The child item can not be displayed all, but sometimes we want to make the ListView as item do not show all, but can slide, to solve this problem need to understand the android on the distribution mechanism of events, my solution is to integrate the ListView, Override Intercepttouchevent to return false to suppress the interception of touch events by the parent ListView and distribute the touch events to Child view for processing. Then, when used, use it as a parent ListView so that the child ListView can slide.
| 1234567891011121314151617181920212223242526272829303132333435363738 |
public class ParentListView extends ListView {public ParentListView(Context context) {super(context);// TODO Auto-generated constructor stub}public ParentListView(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);// TODO Auto-generated constructor stub}public ParentListView(Context context, AttributeSet attrs) {super(context, attrs);// TODO Auto-generated constructor stub}//将 onInterceptTouchEvent的返回值设置为false,取消其对触摸事件的处理,将事件分发给子view@Overridepublic boolean onInterceptTouchEvent(MotionEvent ev) {// TODO Auto-generated method stubreturn false; }} |
| 1234567891011121314 |
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" ><!-- 这里做demo用,直接使用了android中的ListActivity--> <i.test.ParentListView android:id=" @android :id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:dividerHeight="2dip" android:scrollbars="none" /></LinearLayout> |
ListView double-Nested processing