Android,DrawerLayout Fragments CollapsingToolbarLayout

Android,DrawerLayout Fragments CollapsingToolbarLayout,第1张

概述在DrawerLayout的主容器中显示的碎片中是否可以有一个CoordinatorLayout / CollapsingToolbarLayout? 另一个question的答案表明每个片段可以有自己的工具栏.但是,这对于ActionBarDrawerToggle是不正常的,因为它需要一个工具栏才能链接到打开/关闭抽屉行为. 有没有人实现这个,还是你有这个指点?谢谢. 编辑:我一直在努力把一个单 在DrawerLayout的主容器中显示的碎片中是否可以有一个CoordinatorLayout / CollapsingToolbarLayout?

另一个question的答案表明每个片段可以有自己的工具栏.但是,这对于ActionBarDrawerToggle是不正常的,因为它需要一个工具栏才能链接到打开/关闭抽屉行为.

有没有人实现这个,还是你有这个指点?谢谢.

编辑:我一直在努力把一个单一的工具栏放在DrawerLayout中,这意味着一直呆在那里,但是无法让它滚动(在Nexus5 API 22上). this question提到CoordinatorLayout需要作为主视图.所以也许将它插入DrawerLayout(如下所示)将不会工作.

<androID.support.v4.Widget.DrawerLayout ...>    <!-- main content -->    <androID.support.design.Widget.CoordinatorLayout ...>        <androID.support.design.Widget.AppbarLayout ...>            <androID.support.design.Widget.CollapsingToolbarLayout ...>                <ImageVIEw .../>                <androID.support.v7.Widget.Toolbar .../>            </androID.support.design.Widget.CollapsingToolbarLayout>        </androID.support.design.Widget.AppbarLayout>        <androID.support.v7.Widget.RecyclerVIEw .../>    </androID.support.design.Widget.CoordinatorLayout>    <!-- navigation drawer -->    <androID.support.design.Widget.NavigationVIEw ...>        <!-- drawer content -->        <fragment .../>    </androID.support.design.Widget.NavigationVIEw></androID.support.v4.Widget.DrawerLayout>
解决方法 事实上,是的,你可以.我正在寻找同样的事情,从你的问题的链接让我从 Google Blogpost Google Blogpost

无论如何,下面是我的布局文件,对于java代码我没有改变任何东西,片段调用保持不变.

activity_main.xml(主文件)

<?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        layout="@layout/app_bar_main"        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_main"        app:menu="@menu/activity_main_drawer" /></androID.support.v4.Widget.DrawerLayout>

app_bar_main.xml(Navigationbar布局)

<?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=".MainActivity">    <androID.support.design.Widget.AppbarLayout        androID:layout_wIDth="match_parent"        androID:layout_height="192dp"        androID:theme="@style/Apptheme.AppbarOverlay">        <androID.support.design.Widget.CollapsingToolbarLayout            androID:ID="@+ID/toolbar_layout"            androID:layout_wIDth="match_parent"            androID:layout_height="match_parent"            app:layout_scrollFlags="scroll|exitUntilCollapsed">            <androID.support.v7.Widget.Toolbar                androID:ID="@+ID/toolbar"                androID:layout_wIDth="match_parent"                androID:layout_height="?attr/actionbarSize"                androID:background="?attr/colorPrimary"                app:layout_collapseMode="pin"                app:layout_scrollFlags="scroll|enteralways"                app:popuptheme="@style/Apptheme.PopupOverlay" />        </androID.support.design.Widget.CollapsingToolbarLayout>    </androID.support.design.Widget.AppbarLayout>    <include layout="@layout/content_main" />    <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"        androID:src="@androID:drawable/ic_dialog_email" /></androID.support.design.Widget.CoordinatorLayout>

content_main.xml

<?xml version="1.0" enCoding="utf-8"?><androID.support.v4.Widget.nestedScrollVIEw 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"    androID:paddingBottom="@dimen/activity_vertical_margin"    androID:paddingleft="@dimen/activity_horizontal_margin"    androID:paddingRight="@dimen/activity_horizontal_margin"    androID:paddingtop="@dimen/activity_vertical_margin"    app:layout_behavior="@string/appbar_scrolling_vIEw_behavior"    tools:context=".MainActivity"    tools:showIn="@layout/app_bar_main">    <FrameLayout        androID:ID="@+ID/content_main_frame"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent" /></androID.support.v4.Widget.nestedScrollVIEw>

现在你有“DrawerLayout Fragments CollapsingToolbarLayout”

总结

以上是内存溢出为你收集整理的Android,DrawerLayout Fragments CollapsingToolbarLayout全部内容,希望文章能够帮你解决Android,DrawerLayout Fragments CollapsingToolbarLayout所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

    保存