We know that most of the Child classes in ViewGroup have Layout, while the child classes in View are mainly various controls. When you click on the screen, what is its event processing?
OnInterceptTouchEvent is the method in ViewGroup. After you click the screen:
Activity -------> onInterceptTouchEvent ();
ViewGroup --------> onInterceptTouchEvent ();
View ----------------> onInterceptTouchEvent ();
By default, the returned value of onInterceptTouchEvent () is false, so that the touch event can be passed to the next layer. If it is set to true, it cannot be passed.
To block the ImageButton focus in the GridView, you can use the following idea to regard the GridView as a ViewGroup. The Code is as follows:
In java code:
Public class MyGridView extends GridView {
Public MyGridView (Context context, AttributeSet attrs, int defStyle ){
Super (context, attrs, defStyle );
// TODO Auto-generated constructor stub
}
Public MyGridView (Context context ){
Super (context );
// TODO Auto-generated constructor stub
}
Public MyGridView (Context context, AttributeSet attrs ){
Super (context, attrs );
// TODO Auto-generated constructor stub
}
@ Override
Public boolean onInterceptTouchEvent (MotionEvent event ){
// TODO Auto-generated method stub
Return true;
}
}
In xml code:
<Com. example. filemanage. MyGridView
Android: id = "@ + id/gridView"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_below = "@ + id/Title"
Android: layout_above = "@ + id/btnSel"
Android: scrollbars = "vertical"
Android: numColumns = "auto_fit"
Android: verticalSpacing = "10dp"
Android: horizontalSpacing = "10dp"
Android: stretchMode = "columnWidth"/>
Finally, add the android: descendantFocusability = "blocksDescendants" to the layout of the item xml file in the GridView"
In this way, the ImageButon response can be blocked.