刚刚看了一下新的Android支持设计库的演示应用程序。它由Chris在github上提供。通过这个应用程序,CoordinatorLayout被大量使用。此外,许多支持设计库类,如FloatingActionButton、SnackBar、AppBarLayout等,在CoordinatorLayout中使用时都有不同的行为。
有人能说明一下CoordinatorLayout是什么,以及它与安卓系统中的其他ViewGroup有什么不同吗?或者至少提供正确的学习CoordinatorLayout的途径。
发布于 2015-05-29 19:37:40
这就是你要找的。
从医生那里
Design引入了CoordinatorLayout__,该布局为子视图之间的触摸事件提供了额外的控制级别,设计库中的许多组件都利用了这一点。
https://android-developers.googleblog.com/2015/05/android-design-support-library.html
在这个链接中,您将看到所有上述视图的演示视频。
希望这会有所帮助:)
发布于 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中。
<?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:
<?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
开放:

关闭:

发布于 2015-07-02 11:35:13
还有一点要注意。因为OP特别要求
此外,许多支持设计的libabry类,如FloatingActionButton、SnackBar、AppBarLayout等,在CoordinatorLayout中使用时都有不同的行为。
我想是因为这个。
CoordinatorLayout是超级动力的FrameLayout.
FAB Button,SnackBar致力于FrameLayout的概念,而且由于CoordinatorLayout本身具有FrameLayout的功能,它可能会使其他视图的行为有所不同!
https://stackoverflow.com/questions/30536749
复制相似问题