gpt4 book ai didi

java - 折叠工具栏不会随着抽屉布局而折叠

转载 作者:行者123 更新时间:2023-12-02 03:07:43 26 4
gpt4 key购买 nike

这里是初学者。我的折叠工具栏的 react 与常规工具栏一样,没有折叠行为。

这是我有抽屉布局的 Activity 。

    <?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
android:id="@+id/includedLayout"
layout="@layout/app_bar_activity_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_activity_drawer"
app:menu="@menu/activity_drawer_drawer" />

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

在上面的布局中,包含了此布局,其中包含所有其他内容 app_bar_activity_drawer.xml

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

<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>

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

<include layout="@layout/content_activity_drawer" />
</android.support.v4.widget.NestedScrollView>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />

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

这是上面布局中包含的布局 content_activity_drawer.xml

    <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/helloLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".activity_drawer"
tools:showIn="@layout/app_bar_activity_drawer">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello" />


</LinearLayout>

</android.support.constraint.ConstraintLayout>

有什么问题请告知..非常感谢您的支持。

最佳答案

实际上,您没有在布局中添加折叠工具栏,

From the documentation

To add a collapsing toolbar to your layout, place the CollapsingToolbarLayout inside an AppBarLayout. Then, add a Toolbar and any other views as a child to the CollapsingToolbarLayout. Make sure that the entire view structure is inside a CoordinatorLayout to take advantage of CollapsingToolbarLayout’s scrolling and features.

带有折叠工具栏的布局可能看起来像这样:

<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Scrollable view here -->

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="@dimen/tall_toolbar_height">

<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleGravity="top"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"/>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

查看链接了解更多详情

关于java - 折叠工具栏不会随着抽屉布局而折叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57014412/

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