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="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F4F2EE"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical"
android:paddingBottom="2dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="7dp" >

<!-- lang: java -->
   <Button/>
   <ImageView/>
    ........


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="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F4F2EE"
android:orientation="vertical"
>

<include
    android:id="@+id/title_view"
    layout="@layout/title" />

<RelativeLayout>
</RelativeLayout>
 .......
<FrameLayout
    android:id="@+id/above_fl"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/title_view"
    android:background="#00000000" >
</FrameLayout>


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(R.id.above_fl);
    outLineView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (mPopupWindow.isShowing()) {
                AnimationUtils.rotateDown(title_icon);
                mPopupWindow.dismiss();
            }
            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