android– 如何折叠AppBarLayout但不是工具栏的内容

android– 如何折叠AppBarLayout但不是工具栏的内容,第1张

概述这是我的应用程序屏幕:和布局xml:<android.support.v4.widget.NestedScrollViewandroid:id="@+id/content"android:layout_width="match_parent"android:layout_height="match_parent"app:layout_behavior="@string/appbar_s

这是我的应用程序屏幕:

和布局xml:

<androID.support.v4.Widget.nestedScrollVIEw    androID:ID="@+ID/content"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    app:layout_behavior="@string/appbar_scrolling_vIEw_behavior"/><androID.support.design.Widget.AppbarLayout    androID:ID="@+ID/app_bar_layout"    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:animateLayoutChanges="true">    <androID.support.v7.Widget.Toolbar        androID:ID="@+ID/toolbar"        androID:layout_wIDth="match_parent"        androID:layout_height="?attr/actionbarSize"        app:title="@string/app_name"        app:theme="@style/Toolbar"        app:popuptheme="@style/themeOverlay.AppCompat.Dark" /></androID.support.design.Widget.AppbarLayout><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="16dp"    androID:src="@drawable/arrow_right_bold"    app:fabSize="normal" />

我想在滚动时折叠唯一的内容.

我发现我可以将工具栏移出AppbarLayout,但是否有明确的方法?否则,我将强制设置工具栏背景颜色.我没有任何问题,但我认为这是一种肮脏的解决方案:)

所以.如何折叠AppbarLayout但不是工具栏的内容?

解决方法:

如果我理解正确,你想在滚动时折叠标题的一部分.如果是这样的话,@ Nerd的评论链接到一个关于如何做到这一点的好教程.无论如何,我将在这里留下一个CoordinatorLayout用法示例,它可以满足您的需求:

<?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"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:fitsSystemwindows="true">    <androID.support.design.Widget.AppbarLayout        androID:ID="@+ID/app_bar_layout"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:fitsSystemwindows="true"        androID:theme="@style/themeOverlay.AppCompat.Dark.Actionbar">        <androID.support.design.Widget.CollapsingToolbarLayout            androID:ID="@+ID/collapsing_toolbar"            androID:layout_wIDth="match_parent"            androID:layout_height="match_parent"            androID:fitsSystemwindows="true"            app:contentScrim="?attr/colorPrimary"            app:expandedTitlemarginEnd="64dp"            app:expandedTitlemarginStart="48dp"            app:layout_scrollFlags="scroll|exitUntilCollapsed">            <FrameLayout                androID:layout_wIDth="match_parent"                androID:layout_height="match_parent">                <!-- PUT HERE THE PORTION OF THE header YOU WANT TO ColLAPSE WHEN SCRolliNG-->            </FrameLayout>            <androID.support.v7.Widget.Toolbar                androID:ID="@+ID/toolbar"                androID:layout_wIDth="match_parent"                androID:layout_height="?attr/actionbarSize"                app:layout_collapseMode="pin"                app:popuptheme="@style/themeOverlay.AppCompat.light"/>        </androID.support.design.Widget.CollapsingToolbarLayout>    </androID.support.design.Widget.AppbarLayout>    <androID.support.v4.Widget.nestedScrollVIEw        androID:ID="@+ID/scroll"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:clipTopadding="false"        app:layout_behavior="@string/appbar_scrolling_vIEw_behavior">        <!-- YOUR SCRolLABLE CONTENT HERE -->    </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_margin="16dp"        androID:clickable="true"        app:layout_anchor="@ID/app_bar_layout"        app:layout_anchorGravity="bottom|right|end"/></androID.support.design.Widget.CoordinatorLayout>
总结

以上是内存溢出为你收集整理的android – 如何折叠AppBarLayout但不是工具栏的内容全部内容,希望文章能够帮你解决android – 如何折叠AppBarLayout但不是工具栏的内容所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1119427.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存