Auto hide, click blank area control in Android (a small example of event deliver

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

With the maturity of Android Technology, Android applications have been demonstrated by simple effect began to become more and more artistic words, All kinds of animation, Various layout of stack, So this would cause some problems, For example: a listview view item click no reaction, Interface cover on the layer mask after, The following layout control click no reaction.

Today when I modify the bug encountered such a problem.
A, item click no reaction
The reason: a button or checkbox control to your item, by default the focus of focus is the first to the child controls, and ListView based Item can be selected is that it can obtain the Focus focus.
The solution:
1, The root control item layout settings property (android:descendantFocusability= "blocksDescendant"), the following is item layout

<LinearLayout xmlns:android=""
android:paddingTop="7dp" >

<!-- lang: java -->

So Item Layout shielding all child controls access to Focus focus permission, no need for each Item controls in Layout to set the focusable property
2 of all child controls focusable properties of the ListView Item Layout is set to false

Two, the interface layer mask to cover good, lower layout control click no reaction
Reason: the mask to the layer mask to click or touch events to intercept off, Touchevent, the return value is true, the consumed in this event, the return value is false, are not consumed, will continue to pass on.
In the View and Touch events related to dispatchTouchEvent, interceptTouchEvnet, onTouchEvent three. DispatchTouchEvent is responsible for the distribution of events, After the event delivery from activity, The first arrival is the most top view dispatchTouchEvent , Then it distributes, Returns false if the , The interceptTouchEvent method to the view to decide whether to intercept this, If interceptTouchEvent returns true , That is blocked off, Then give it onTouchEvent to handle, If interceptTouchEvent returns false , Then transfer to view , By view dispatchTouchEvent and began to distribute this event.

If the event is passed to a layer of view onTouchEvent, this method returns false, then the event will be passed to the view, it is onTouchEvent to receive

The solution:

<RelativeLayout xmlns:android=""

    layout="@layout/title" />

    android:background="#00000000" >

The above FrameLayout is above cover a layer of transparent cover, if you do not take any measures only the cover to the layout of the above, click on the following the control when it is no response, because the FrameLayout has to click or touch events to intercept,
Then you can use the following code makes the click event through the hood, see the code

private FrameLayout outLineView;

outLineView = (FrameLayout) findViewById(;
    outLineView.setOnTouchListener(new OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            if (mPopupWindow.isShowing()) {
            return false;

OnTouch outLineView method returns false, then click or touch events to wear to the layer below.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Alvin at January 14, 2014 - 5:13 AM