如何重新创建Android快速设置滑动面板? [英] How to recreate Android quick settings sliding panel?

本文介绍了如何重新创建Android快速设置滑动面板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我想重新创建与大家都知道的Lollipop +快速设置面板非常相似的东西.

In my app I want to recreate something that is very similar to the Lollipop+ quick settings panel that everyone knows.

即:通过单击或拖动标题,我希望面板从标题下方向下滑动并向下推现有内容.

现在应用于我的应用程序,标题是工具栏,主要内容是RecyclerView,其中显示了博客文章列表.通过单击或拖动工具栏,我希望出现一个面板以显示有关博客的一些统计信息.像这样:

Applied to my app now, the header is a Toolbar and the main content is a RecyclerView showing a list of blog posts. By clicking or dragging the Toolbar, I'd like a panel to appear to show some stats about the blog. Like so:

我一直在搞砸真棒(但很复杂)的Android设计支持库.它具有出色的功能,可滚动和设计应用程序栏与主要内容之间的交互.但是效果很难达到.

I have been messing around with the awesome (but complex) Android Design Support Library. It has great functionality for scrolling and designing the interaction between the app bar and the main content. But the effect is hard to achieve.

我研究了 CollapsingToolbarLayout 但不能以将内容扩展到主Toolbar以下 的方式使用它.我还研究了 SlidingUpPanel 库,但无法使其将内容压下,只需将鼠标悬停即可.总体而言,我对CoordinatorLayoutCollapsingToolbarLayout和滚动Behavior应该如何交互互动感到迷茫...

I have studied the CollapsingToolbarLayout but couldn't use it in a way that the content is expanded below the main Toolbar. I have also studied the SlidingUpPanel library but couldn't make it push the content down, simply hover. Overall, I'm a bit lost as to how CoordinatorLayout, CollapsingToolbarLayout and scrolling Behaviors should interact together...

有人知道要重新创建这种快速设置"效果吗?另外,也许有人知道我应该在哪里寻找AOSP中快速设置"的代码?

Does anyone know to recreate this "quick settings" effect? Alternatively, maybe someone knows where I should look to find the code for the Quick Settings in AOSP?

非常感谢!

推荐答案

Head Upadhyay .

关键是要依靠CoordinatorLayout并描述两个自定义的Behavior:一个用于滑动面板,另一个用于主要内容.我实际上已经为此创建了一个库,因为这可能会在将来对其他人有所帮助: SubAppBarPanel . 查看实际效果.

The key was to rely on the CoordinatorLayout and to describe two custom Behaviors: one for the sliding panel, another one for the main content. I have actually created a library for this purpose as this may help other people in the future: SubAppBarPanel. See it in action.

示例代码:

<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.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:clickable="true"
            android:foreground="?selectableItemBackground" />

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

    <com.davidferrand.subappbarpanel.SubAppBarPanel
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:panel_expanded="false"
        app:panel_offset="10dp"
        app:panel_slidingQuantity="85%">

        <!-- Content of the sliding panel -->

    </com.davidferrand.subappbarpanel.SubAppBarPanel>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="com.davidferrand.subappbarpanel.SubAppBarPanel$ScrollingViewBehavior">

        <!-- Main content -->

    </FrameLayout>

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

注意:拖动行为仍然是待办事项.

Note: dragging behavior is still a TODO.

这篇关于如何重新创建Android快速设置滑动面板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆