android - 如何在没有嵌套 ScrollView 的情况下实现新 Material gmail 工具栏?

标签 android material-design material-ui toolbar

我想在没有嵌套 ScrollView 的情况下实现类似工具栏的新 gmail,它可以滚动,但是当向下滚动时背景应该是可见的。

它看起来像这样: enter image description here

最佳答案

这不是嵌套的 ScrollView ,它是 recyclerView . 如果你想要这样的搜索栏,你可以使用 CardView 来实现。和 Edittext 或使用 Material searchba图书馆。您可以使用 frameLayout 或 CoordinatorLayout 将其锁定在该位置。

这是我制作的示例屏幕!

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:background="#dadada"
        android:layout_height="match_parent">

        <android.support.v7.widget.CardView
            app:cardUseCompatPadding="true"
            android:layout_margin="8dp"
            app:cardCornerRadius="8dp"
            android:layout_width="match_parent"
            android:layout_height="64dp">

            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:id="@+id/imageView2"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_marginStart="8dp"
                    android:src="@drawable/ic_menu_black_24dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <EditText
                    android:id="@+id/editText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="16dp"
                    android:layout_marginTop="8dp"
                    android:layout_marginBottom="8dp"
                    android:background="@android:color/transparent"
                    android:hint="Search..."
                    android:minWidth="100dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintStart_toEndOf="@+id/imageView2"
                    app:layout_constraintTop_toTopOf="parent" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_marginTop="8dp"
                    android:layout_marginEnd="8dp"
                    android:layout_marginBottom="8dp"
                    android:src="@drawable/ic_search_black_24dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

            </android.support.constraint.ConstraintLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </android.support.v7.widget.RecyclerView>

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

这是结果。

enter image description here

关于android - 如何在没有嵌套 ScrollView 的情况下实现新 Material gmail 工具栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54956542/

相关文章:

flutter - 如何在 Flutter 中使用 Material 3 表面色调?

Android浏览器历史URI?

android - 标签栏从 android studio 中消失了

mobile - Flutter:根据验证更改状态

javascript - 当使用 Vue 隐藏或显示元素时,MDL 样式会丢失

javascript - 使用我自己的值更新 Materui LinearProgressWithLabel 进度值

javascript - 在自动完成中禁用退格删除选项

reactjs - 如何将 Material UI 中的组件居中并使其具有响应能力?

java - 当我尝试启动我的android应用程序(A viewFlipper)时出错

android - 如何使用 libstreaming 在 rtsp 中发送多播音频并在 vlc 播放器中接收