我的布局如下:

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/main_content"
    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="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

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

    <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</android.support.design.widget.CoordinatorLayout>

我把Fragment加到FrameLayout里,把它们换掉.我的Fragment条中有一条是列表,它的布局如下:

<android.support.v7.widget.RecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

我的问题是toolbar is drawn over the list.我试图通过将CoordinatorLayout的内容包装成LinearLayout来解决这个问题,解决了透支问题,但这样appbar滚动行为就不再有效了.

如有任何帮助,我们将不胜感激!

推荐答案

取该属性

app:layout_behavior="@string/appbar_scrolling_view_behavior"

go 掉RecyclerView号,把它放在你想要在Toolbar号下面显示的FrameLayout号上.

我发现滚动视图行为所做的一件重要事情是在工具栏下方布局组件.因为FrameLayout的子代将滚动(RecyclerView),所以CoordinatorLayout将获得移动Toolbar的滚动事件.


另一件需要注意的事情是:布局行为将导致将FrameLayout的高度调整为as if the 101 is already scrolled,并且在Toolbar完全显示的情况下,整个视图被简单地向下推,使得视图的底部低于CoordinatorLayout的底部.

这让我大吃一惊.我原以为视图会随着工具栏的上下滚动而动态调整大小.因此,如果视图底部有一个带有固定组件的滚动组件,则在完全滚动Toolbar之前,您不会看到底部组件.

因此,当我想在UI底部锚定一个按钮时,我解决了这个问题,将按钮放在CoordinatorLayout(android:layout_gravity="bottom")的底部,并在工具栏下方的视图中添加一个等于按钮高度的底部边距.

Android相关问答推荐

ava.lang. ClassNotFound异常:没有找到类com.example.myapp.MyApp"

如何允许我的应用程序在Android 10上运行,同时目标是API 33

了解数据加载在Kotlin中的工作原理

无法在Android Gradle中同步Chaquopy版本

react 本机生成失败,出现异常.错误:无法确定';<;宏/>;的类型

我怎样才能画一条线在喷气背包组成和有一个自定义的角落?

页面更改时不显示 cogo toast 消息

触发PurchasesUpdatedListener回调时,billingClient.launchBillingFlow之前设置的成员变量丢失

Jetpack Compose X.dp 性能问题?

Gradle在我的Android Compose项目中继续推广依赖版本

retrofit2.HttpException: HTTP 401

在 compose 中做可变状态堆栈

如何在 React Native 中调试网络响应

LazyColumn 项目,隐式接收器无法在此上下文中调用单元

如何放置在柱子的角落(底端)

viewModel 的可变值状态不起作用

处理程序 postDelayed 方法不起作用,kotlin 应用程序卡在启动画面上

如何将设备屏幕位置转换为发送事件位置?

Android Jetpack Compose - 找不到 R.drawable?

如何使用jetpack compose实现布局,其中图标在列布局上是绝对位置