gpt4 book ai didi

Android设计库CoordinatorLayout、AppBarLayout和DrawerLayout

转载 作者:IT老高 更新时间:2023-10-28 23:34:04 25 4
gpt4 key购买 nike

我在 API 22 上使用 Android 设计库。我想:

  1. 有一个 Toolbar 和一个 DrawerLayout,里面有一个 RecyclerView
  2. 让 DrawerLayout 位于工具栏下方;例如,当工具栏可见时,抽屉的主要内容应在其下方,(左)抽屉也应在其下方,以便在展开时,工具栏仍然可见
  3. 当回收站 View 向下滚动时,工具栏会滚出屏幕

这甚至可能吗?我很难与#2 和#3 结婚。现在的方式是工具栏始终位于抽屉布局上方,覆盖回收器中的第一个条目,以及左侧抽屉的顶部。这是我的布局文件(不完整,但显示了我的结构):

<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

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

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"/>

</android.support.v4.widget.DrawerLayout>

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<Toolbar
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"/>

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

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

看起来 RecyclerView 的 app:layout_behavior="@string/appbar_scrolling_view_behavior"设置没有效果,因为删除后的行为是一样的。

我尝试添加一个 RelativeLayout 作为 CoordinatorLayout 的子项,以定义抽屉位于工具栏等下方,但似乎没有任何效果。

我想通过图书馆实现的目标是否可行?

最佳答案

如果您想查看汉堡图标和箭头的动画,请尝试以下操作。如果您包含 NavigationView 的上边距 (layout_marginTop),它将向下移动。

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/navigation_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways" />

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

<!-- main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

<!-- The navigation drawer -->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="@menu/drawer_menu"/>

</android.support.v4.widget.DrawerLayout>

关于Android设计库CoordinatorLayout、AppBarLayout和DrawerLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30719369/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com