协调布局重叠底部按钮

3
我正在设计我的XML,最初使用的是一个Coordinator Layout,它与Action ToolBar重叠了。我查阅资料后发现添加app:layout_behavior="@string/appbar_scrolling_view_behavior" 属性可以解决此问题。
然而,在我的XML中,我仍然遇到Coordinator Layout覆盖Preview屏幕底部按钮的问题。虽然我知道这些按钮实际上在手机上,但我仍然困惑为什么布局会延伸到这些项上。如下图所示,布局重叠了底部按钮,我不记得在引入Coordinator Layout之前曾看到过这种情况:
<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2.2" />

    <LinearLayout
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:layout_height="0dp"
        android:layout_weight="2">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
             />

        <CheckBox
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
             />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1.3">

    </LinearLayout>

</LinearLayout>

See the Layout overlapping the buttons

2个回答

5
当您添加app:layout_behavior="@string/appbar_scrolling_view_behavior"时,它的基本作用是将该布局设置在Toolbar下方,并将两个布局放入类似于ScrollView的布局中。由于在该布局顶部有一个Toolbar,因此该整个布局(形成的ScrollView)会被Toolbar的高度向下推。

感谢您的澄清,换句话说,没有“修复”,但向用户呈现的内容实际上将是一个ScrollView。我想我可以修改LinearLayout中底部子项的高度,以防止它们重叠。此外,我认为如果我将顶级父项更改为LinearLayout,也可以解决这个问题。 - tccpg288
@tccpg288 我也遇到了同样的问题。你找到解决方法了吗? - Rohan
我使用了上面的解决方案,它帮助解决了问题。如果你想发表新帖并添加你的代码,可能会有所帮助,但最终当我在手机上运行时,我没有遇到这个问题。 - tccpg288

0

曾遇到类似问题,通过添加以下内容解决:

 android:fitsSystemWindows="true"

返回主父级,通常是承载其余部分的android.support.design.widget.CoordinatorLayout。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接