阻止FrameLayout中的单击事件

时间:2017-03-28 21:28:23

标签: android layout click android-framelayout

我有FrameLayoutFrameLayout我有两个观点,一个是ViewPager,另一个是LinearLayoutLinearLayout就像一个窗口,所以它有一些按钮。我使用visibility属性显示和隐藏LinearLayout。问题是,当我显示LinearLayout时,它会覆盖ViewPager,但用户仍然可以滚动ListView内的ViewPager。我想阻止所有点击事件到后面的视图。

XML看起来像这样:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          xmlns:tools="http://schemas.android.com/tools"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@color/colorBeige"
          android:orientation="vertical">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar_diner_food"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@android:color/white"
    android:contentInsetLeft="0dp"
    android:contentInsetStart="0dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:titleTextColor="@android:color/white"
    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp"/>

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.design.widget.TabLayout
            android:id="@+id/tab_layout_diner_food"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:background="@android:color/white"/>

        <android.support.v4.view.ViewPager
            android:id="@+id/view_pager_diner_food"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/linea_layout_filter"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorBlackAlpha">

        <com.wonderkiln.blurkit.BlurLayout
            android:id="@+id/blurLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clipChildren="true"
                android:orientation="vertical">

                <SeekBar
                    android:id="@+id/seek_bar"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="61dp"/>
            </LinearLayout>
        </com.wonderkiln.blurkit.BlurLayout>
    </LinearLayout>
</FrameLayout>

2 个答案:

答案 0 :(得分:0)

当您点击ListView的任何部分时,它会阻止LinearLayout中的滚动。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@color/colorBeige"
      android:orientation="vertical">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_diner_food"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/white"
android:contentInsetLeft="0dp"
android:contentInsetStart="0dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:titleTextColor="@android:color/white"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"/>

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout_diner_food"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:background="@android:color/white"/>

    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager_diner_food"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>

</LinearLayout>

<LinearLayout
    android:id="@+id/linea_layout_filter"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorBlackAlpha">

    <com.wonderkiln.blurkit.BlurLayout
        android:id="@+id/blurLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipChildren="true"
            android:orientation="vertical">

            <SeekBar
                android:id="@+id/seek_bar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="61dp"/>
        </LinearLayout>
    </com.wonderkiln.blurkit.BlurLayout>
</LinearLayout>
</FrameLayout>

答案 1 :(得分:0)

将onTouchEvent方法添加到顶部位置的视图,然后返回true。 True将告诉事件冒泡,事件被消耗,因此阻止事件冒泡到其他视图。

protected boolean onTouchEvent (MotionEvent me) {
    return true;
}

以防止在ListView下滚动 要禁用任何点击,您可以使用

view.setClickable(false);