How to disable behind view click event Framelayout

前端 未结 9 1312
遥遥无期
遥遥无期 2020-12-04 20:53

Here i have one view pager activity which has one imageview and 2 overlay bars. there overlay bars i made using android xml file layout itself.

Here my requirement i

相关标签:
9条回答
  • 2020-12-04 21:08

    android:clickable="true" for top and bottom bar.

    or give each FrameLayout an onClickListener.

    0 讨论(0)
  • 2020-12-04 21:08

    By default, some controls have clickable property as true. But the layout doesn't. For layout, we have to make them explicitly clickable so that it will grab the events of clicks or touches and will not let it pass to background views. This is how we do it:

    android:clickable="true"
    android:focusable="true"
    android:focusableInTouchMode="true"
    

    Add these lines to all your layouts, so that it will grab/absorb events and will not let it pass to background views.

    0 讨论(0)
  • 2020-12-04 21:08

    @gordon1hd1 answer is correct but for those who are still confused, I am adding my layout which contains a FrameLayout as parent and a LinearLayout and twoImageViews as childs.

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">         
         <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/scroll_parent"
                android:orientation="horizontal" />
        <ImageView
            android:id="@+id/ivArrowLeft"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="4dp"
            android:src="@drawable/actionbar_back"
            android:layout_gravity="left|center_vertical"
            android:background="#3f808080"
            android:clickable="true"
            />
        <ImageView
            android:id="@+id/ivArrowRight"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="4dp"
            android:src="@drawable/actionbar_back"
            android:layout_gravity="right|center_vertical"
            android:background="#3f808080"
            android:rotation="180"
            android:clickable="true"
            />
    </FrameLayout>
    

    Previously, the Linearlayout was also intercepting touch events when either of ImageViews were pressed. Adding android:clickable="true" to both ImageViews resolved the issue.

    If you are also facing this type of issue, add android:clickable="true" to the view you want to trap the clicking event.

    0 讨论(0)
  • 2020-12-04 21:09

    A better way is to set the top and bottom frame to be clickable, with:

    android:clickable="true"
    

    Doing so will make sure that the view/frame itself will trap all clicking events, and will not pass it through the view behind it. Note this method works for all layout/view/controls, but many controls (such as buttons) already have this function on by default.

    0 讨论(0)
  • 2020-12-04 21:17

    just add this to each of your framelayout view containers so that absorb the click:

      android:clickable="true"
        android:focusable="true"
        android:focusableInTouchMode="true"
    
    0 讨论(0)
  • 2020-12-04 21:20

    Simply, Set android:clickable="true" in xml to your foreground view.

    0 讨论(0)
提交回复
热议问题