Android 防止框架布局中的单击事件
我有一个Android 防止框架布局中的单击事件,android,layout,click,android-framelayout,Android,Layout,Click,Android Framelayout,我有一个FrameLayout,在FrameLayout中我有两个视图,一个是ViewPager,另一个是LinearLayout,LinearLayout就像一个窗口,所以它有一些按钮。我使用可见性属性显示和隐藏线性布局。问题是当我显示线性布局时,它覆盖了查看页面,但用户仍然可以在查看页面内滚动列表视图。我想阻止所有点击事件进入后面的视图 XML如下所示: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/an
FrameLayout
,在FrameLayout
中我有两个视图,一个是ViewPager
,另一个是LinearLayout
,LinearLayout
就像一个窗口,所以它有一些按钮。我使用可见性属性显示和隐藏线性布局
。问题是当我显示线性布局时,它覆盖了查看页面
,但用户仍然可以在查看页面
内滚动列表视图
。我想阻止所有点击事件进入后面的视图
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>
当您单击线性布局的任何部分时,它将阻止在列表视图中滚动
<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>
将onTouchEvent方法添加到具有top position的视图中,然后返回true。True将告诉冒泡事件该事件已被使用,因此防止事件冒泡到其他视图
protected boolean onTouchEvent (MotionEvent me) {
return true;
}
以防止在ListView下滚动
以及禁用您可以使用的任何单击
view.setClickable(false);
为什么使用框架布局?框架布局基本上用于框架结构设计。可以按帧添加视图。当第一帧可见时,则无法访问第二帧布局的第一个子帧将位于底部,最后一个子帧将位于顶部位置它无法工作。我将结构更改为FrameLayout,但由于TablLayout,我仍然可以滚动,您可以滚动。你需要为FrameLayout为TabFragment Ui创建另一个Ui,或者只是为了测试我的代码,隐藏TableLayout代码,我的代码会很好地工作。我在你的问题中编辑的代码会很好地工作,我也为你的问题编辑了我的答案&看看这个,让我知道这是否有效not@NarendraSorathiya它不起作用。