首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >CoordinatorLayout是什么?

CoordinatorLayout是什么?
EN

Stack Overflow用户
提问于 2015-05-29 18:35:49
回答 7查看 81.8K关注 0票数 105

刚刚看了一下新的Android支持设计库的演示应用程序。它由Chris在github上提供。通过这个应用程序,CoordinatorLayout被大量使用。此外,许多支持设计库类,如FloatingActionButtonSnackBarAppBarLayout等,在CoordinatorLayout中使用时都有不同的行为。

有人能说明一下CoordinatorLayout是什么,以及它与安卓系统中的其他ViewGroup有什么不同吗?或者至少提供正确的学习CoordinatorLayout的途径。

EN

Stack Overflow用户

发布于 2017-01-26 19:33:12

什么是CoordinatorLayout?别让这个花哨的名字愚弄你,它不过是类固醇的FrameLayout而已。

要最好地理解CoordinatorLayout是什么/做什么,首先必须理解/记住协调意味着什么。

如果你用谷歌搜索这个词

坐标

你得到的是:

我认为这些定义有助于描述CoordinatorLayout自己做了什么,以及其中的视图是如何运行的。

A CoordinatorLayout (a ViewGroup)带来了a(̶a̶̶c̶o̶m̶p̶l̶e̶x̶̶,̶c̶t̶i̶v̶t̶y̶o̶t̶y̶o̶r̶a n r o r r o r,n into )的不同元素(子视图),a(̶a a̶̶c̶o̶m̶p̶l̶e̶x̶̶a̶c̶t̶i̶v̶t̶y̶o̶t̶y̶)a n r o r o r_c_i_i_z,t_s,t_i_o_s,x_n布局为一个和谐有效的关系:

在CoordinatorLayout的帮助下,子视图和谐地协同工作,以实现令人敬畏的行为,例如

拖曳的,滑动的,投掷的,或任何其他的手势。

CoordinatorLayout内部的视图与其他视图协商,以便通过指定这些行为有效地协同工作。

CoordinatorLayout是一个超级酷的材料设计功能,帮助创建有吸引力和协调的布局。

您所要做的就是将您的子视图封装在CoordinatorLayout中。

代码语言:javascript
运行
复制
<?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"
 android:fitsSystemWindows="true"
 tools:context="com.byte64.coordinatorlayoutexample.ScollingActivity">

 <android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/app_bar_height"
    android:fitsSystemWindows="true"
    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"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">



        <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/AppTheme.PopupOverlay" />
        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

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

<include layout="@layout/content_scolling" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin"
    app:layout_anchor="@id/app_bar"
    app:layout_anchorGravity="bottom|end"
    app:srcCompat="@android:drawable/ic_dialog_email" />

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

和content_scrolling:

代码语言:javascript
运行
复制
<?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"
 app:layout_behavior="@string/appbar_scrolling_view_behavior"
 tools:context="com.byte64.coordinatorlayoutexample.ScollingActivity"
 tools:showIn="@layout/activity_scolling">

 <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/text_margin"
    android:text="@string/large_text" />

 </android.support.v4.widget.NestedScrollView>

这给了我们一个可以滚动的布局,可以折叠工具栏并隐藏FloatingActionButton

开放:

关闭:

票数 53
EN
查看全部 7 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30536749

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档