【发布时间】:2017-01-06 11:14:27
【问题描述】:
我有 CoordinatorLayout 的 xml 文件
<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical"
android:visibility="visible"
android:gravity="center_horizontal">
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp">
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
app:tabBackground="@drawable/my_tab_item_bg_selector"
app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabMode="fixed"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
我还有另一个 xml 文件,我将其放在协调器布局中
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nestedScrollData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:id="@+id/layoutDataDispatchContacts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal">
<LinearLayout
android:id="@+id/layoutFullTableDispatchContacts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:background="@drawable/layout_block_background">
<LinearLayout
android:id="@+id/tableLinearLayoutDispatchContacts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal">
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
我发现了空白区域的错误,它覆盖了我的窗口的一部分并且不可点击。这是在下面的屏幕截图中: unclickable inactive bottom space 我注意到,当我从 ViewPager 中删除 app:layout_behavior="@string/appbar_scrolling_view_behavior" 时,错误消失了。但是我的标签名称也消失了。我认为它会创建一些不可见的工具栏或类似的东西。
【问题讨论】:
-
在你的情况下,那个空白不是'layoutBottom'的区域吗?
-
不,我已经更改了代码,删除了不必要的
-
我找到了一些愚蠢的解决方案。
-
我从 ViewPager 和 NestedScrollView 中删除了 app:layout_behavior="@string/appbar_scrolling_view_behavior",将 AppBarLayout 和 TabLayout 中的 android:layout_height="wrap_content" 替换为 android:layout_height="45dp" 并添加了 android :layout_marginTop="45dp" 到 ViewPager。不是最好的解决方案,但它有效。问题确实出在 appbar_scrolling_view_behavior 中。它增加了空的底部空间。我什至不在乎为什么。
-
您在 ViewPager 和 NestedScrollView 中都添加了导致问题的 appbar_scrolling_view_behavior,它应该仅添加到 CoordinatorLayout 的直接子项中,在您的情况下是 ViewPager。 NestedScrollView 是子布局的一部分。
标签: android coordinator-layout