android - 如何在没有嵌套滚动视图的情况下实现新材料 gmail 工具栏?
问题描述
我想在没有嵌套滚动视图的情况下实现新的类似 gmail 的工具栏,它可以滚动,但是当向下滚动时,背景应该是可见的。
它看起来像这样:
解决方案
它不是嵌套的滚动视图,它是recyclerView。如果你想要这样的搜索栏,你可以使用CardView和 Edittext 或者使用Material searchbar library。您可以使用 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>
这是结果。
推荐阅读
- javascript - html/javascript 如何知道属性是布尔值而不是字符串
- javascript - 未知数量的承诺取决于先前承诺的结果?
- java - android studio java 翻译语言
- python - 模型不学习
- javascript - 使用ajax发送消息
- spring-aop - 方法调用和方法执行——Spring AOP
- python - 谷歌地理编码 API OVER_QUERY_LIMIT 问题
- fullscreen - 观看全屏视频时防止 xautolock/i3lock
- python - 如何使用 tkinter 条目小部件?
- haskell - 未能在我自己定义的数据结构上使用地图