垂直抽屉布局或侧滑面板布局

41
最新的Android支持库引入了DrawerLayout,用于实现常见的UX模式,即通过向右或向左滑动来显示导航菜单。
我想要的是一个垂直的DrawerLayout,具有相同的API,可以从我的布局顶部/底部向下/向上拉出。
自从4.2版本开始,旧的SlidingDrawer已经被弃用,我没有听说有新的小部件实现了相同的功能。 DrawerLayout是否能够通过扩展来实现垂直滑动UX模式? 谷歌是否提供一些不同的小部件来实现此功能?
例如,Google Music就有非常类似我所要实现的向上拉播放器的功能。 enter image description here
3个回答

45

2
干得好。这正是我在寻找的,你让很多人的生活变得更加轻松了。我想知道为什么谷歌一直把这个留给自己。顺便说一句:你在演示中的梗图让我开心了一整天 :) - Mario Lenci
有没有可能添加Maven支持? - Marco RS
嘿,Marco,这不是一个库,要使用这个视图,只需将其复制到您的项目中即可。 - tokudu
嘿@tokudu,我该如何将它添加到我的IntelliJ项目中? - juliano.net
如何将其作为DrawerLayout的子项使用?每当我将其作为DrawerLayout的子项时,它不会随着拖动而向上移动,仍然停留在底部。有什么想法吗? - jeevs
显示剩余2条评论

12

2
非常感谢您的提示,我一直在寻找比umano Sliding Panel更好的解决方案。 - gtRfnkN
这是一个很好的教程,按照谷歌规范添加底部工作表。https://code.tutsplus.com/articles/how-to-use-bottom-sheets-with-the-design-support-library--cms-26031 - Nick N
答案中的链接已经过时,但这个链接指向了该类:https://developer.android.com/reference/android/support/design/widget/BottomSheetBehavior - ThomasW

1
现在,使用BottomSheetBehavior更有意义,您可以在https://code.tutsplus.com/articles/how-to-use-bottom-sheets-with-the-design-support-library--cms-26031上找到有关如何设置它的更多信息。
基本上,您需要设置主要内容和滑动内容。 BottomSheetBehavior仅适用于从底部向上滑动的面板。
它具有非常简单的设置,BottomSheetBehavior甚至可以立即使用。只需编写一个android.support.design.widget.CoordinatorLayout布局,并在其中放置另一个View(甚至将wrap_content作为layout_height参数的值),例如像这样的LinearLayout:
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:behavior_hideable="true"
        app:behavior_peekHeight="56dp"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

        <!-- Your content goes here -->

    </LinearLayout>

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

在我的情况下,我会在一个Fragment中填充这个布局,并将其添加到希望启用SlidingSheetBehaviorActivity中。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接