Android – 协调器布局,抽屉布局和碎片

Android – 协调器布局,抽屉布局和碎片,第1张

概述我花了一些时间试图实现这一点,并做了我的研究,但无法使其工作. 在Chris Banes的 cheesesquare示例中,当滚动ViewPager时,他使工具栏滚动. ViewPager直接包含在他的抽屉布局中,就在NaviagtionView之前. <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.and 我花了一些时间试图实现这一点,并做了我的研究,但无法使其工作.
在Chris Banes的 cheesesquare示例中,当滚动VIEwPager时,他使工具栏滚动. VIEwPager直接包含在他的抽屉布局中,就在NaviagtionVIEw之前.
<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/drawer_layout"    androID:layout_height="match_parent"    androID:layout_wIDth="match_parent"    androID:fitsSystemwindows="true">    <!-- THIS CONTAINS COORDINATOR LAYOUT with APPbar LAYOUT + VIEWPAGER -->    <include layout="@layout/include_List_vIEwpager"/>    <androID.support.design.Widget.NavigationVIEw        androID:ID="@+ID/nav_vIEw"        androID:layout_height="match_parent"        androID:layout_wIDth="wrap_content"        androID:layout_gravity="start"        androID:fitsSystemwindows="true"        app:headerLayout="@layout/nav_header"        app:menu="@menu/drawer_vIEw"/></androID.support.v4.Widget.DrawerLayout>

include_List_vIEwpager文件是这样的:

<?xml version="1.0" enCoding="utf-8"?><androID.support.design.Widget.CoordinatorLayout    androID:ID="@+ID/main_content"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent">    <androID.support.design.Widget.AppbarLayout        androID:ID="@+ID/appbar"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:theme="@style/themeOverlay.AppCompat.Dark.Actionbar">        <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_scrollFlags="scroll|enteralways"            app:popuptheme="@style/themeOverlay.AppCompat.light"/>        <androID.support.design.Widget.TabLayout            androID:ID="@+ID/tabs"            androID:layout_wIDth="match_parent"            androID:layout_height="wrap_content"/>    </androID.support.design.Widget.AppbarLayout>    <androID.support.v4.vIEw.VIEwPager        androID:ID="@+ID/vIEwpager"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        app:layout_behavior="@string/appbar_scrolling_vIEw_behavior"/>    <androID.support.design.Widget.floatingActionbutton        androID:ID="@+ID/fab"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_gravity="end|bottom"        androID:layout_margin="@dimen/fab_margin"        androID:src="@drawable/ic_done"/></androID.support.design.Widget.CoordinatorLayout>

我想有一个FrameLayout(或nestedScrollVIEw)而不是VIEwPager.然后,当用户点击抽屉布局项时,我可以在其中动态加载片段,并且所有这些片段都有一个很好的动画工具栏.到目前为止,在调用的片段中 *** 作时,我无法使工具栏滚动.我想知道它是否可能.

有人做到了吗?非常感谢任何指针.

解决方法
<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.support.design.Widget.AppbarLayout        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:theme="@style/themeOverlay.AppCompat.Dark.Actionbar">        <androID.support.v7.Widget.Toolbar            androID:ID="@+ID/mToolbar"            androID:layout_wIDth="match_parent"            androID:layout_height="?attr/actionbarSize"            app:layout_scrollFlags="scroll|enteralways"            app:popuptheme="@style/themeOverlay.AppCompat.light"/>        <androID.support.design.Widget.TabLayout            androID:ID="@+ID/tabLayout"            androID:layout_wIDth="match_parent"            androID:layout_height="wrap_content"/>    </androID.support.design.Widget.AppbarLayout>    <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/drawer_layout"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:fitsSystemwindows="true"        app:layout_behavior="@string/appbar_scrolling_vIEw_behavior">        <androID.support.v4.vIEw.VIEwPager        androID:ID="@+ID/tab_vIEwpager"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"/>        <androID.support.design.Widget.NavigationVIEw        androID:ID="@+ID/navigation_vIEw"        androID:layout_wIDth="wrap_content"        androID:layout_height="match_parent"        androID:layout_gravity="start"        app:headerLayout="@layout/drawer_header"        app:menu="@menu/drawer"/>    </androID.support.v4.Widget.DrawerLayout></androID.support.design.Widget.CoordinatorLayout>

CoordinatorLayout必须是所有视图的父级. DrawerLayout获取layout_behavior.由于您想要与vIEwpager的元素进行交互,因此它需要位于DrawerLayout的顶视图中.

总结

以上是内存溢出为你收集整理的Android – 协调器布局,抽屉布局和碎片全部内容,希望文章能够帮你解决Android – 协调器布局,抽屉布局和碎片所遇到的程序开发问题。

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

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

原文地址: http://outofmemory.cn/web/1134956.html

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

发表评论

登录后才能评论

评论列表(0条)

保存