仅查看了新的Android支持设计库的演示应用程序。由Chris Banes在github上提供。在整个应用程序中,CoordinatorLayout
被大量使用。此外,在FloatingActionButton
中使用时,许多支持设计库类(例如SnackBar
,AppBarLayout
,CoordinatorLayout
等)的行为也有所不同。
[有人可以说明CoordinatorLayout
是什么,以及它与Android中其他ViewGroup
的不同之处,或者至少提供了学习CoordinatorLayout
的正确方法。
这是您在寻找的文档中的内容:
设计库引入了CoordinatorLayout
,这是一种布局,可以对子视图之间的触摸事件进行额外的控制,这是设计库中许多组件所利用的。
https://android-developers.googleblog.com/2015/05/android-design-support-library.html
在此链接中,您将看到上述所有视图的演示视频。
希望这会有所帮助:)
什么是CoordinatorLayout?不要让这个花哨的名字欺骗了您,它不过是类固醇上的FrameLayout
为了最好地了解CoordinatorLayout
是/做什么,您必须首先了解/牢记对坐标的含义。
[如果您用谷歌这个词
坐标
这就是您得到的:
我认为这些定义有助于描述CoordinatorLayout本身的功能及其内部视图的行为。
<<[在CoordinatorLayout的帮助下,子视图可以和谐地协同工作,以实现令人敬畏的行为,例如
拖动,轻扫,猛击或其他任何手势。[CoordinatorLayout中的视图通过与其他人协商以便通过指定这些Behaviors来有效地协同工作
CoordinatorLayout是Material Design的超酷功能,可帮助创建有吸引力且协调的布局。
您要做的就是将您的子视图包装在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的布局
打开:
已关闭: