美文网首页程序员@IT·互联网Android知识
android CoordinatorLayout 控件介绍

android CoordinatorLayout 控件介绍

作者: 666swb | 来源:发表于2016-05-27 10:49 被阅读362次

翻译

shot-fy.png

这个控件就是协调它里面View的行为

from

shot-from.png

可以看到:该控件是继承了线性布局的自定义view,经过了一系列的封装生成的.

what

shot-descrip.png

个人翻译:

CoordinatorLayout is a super-powered FrameLayout

CoordinatorLayout 是加强版的FrameLayout

CoordinatorLayout is intended for two primary use cases:
1: a top-level application decor or chrome layout
2: a container for a specific interaction with one or more child views

CoordinatorLayout 有两个主要的用处:
1. 作为顶层布局或者chrome layout
2. 作为一个协调多个view的容器

By specifying Behaviors for child views of a CoordinatorLayout you can provide many different interactions within a single parent and those views can also interact with one another. View classes can specify a default behavior when used as a child of a CoordinatorLayout using the DefaultBehavior annotation.

CoordinatorLayout是通过指定子view的Behaviors来处理子view的关系的。当Coordinator的子类使用DefaultBehavior的动画,那么view类可以指定一个默认的behavior。

Behaviors may be used to implement a variety of interactions and additional layout modifications ranging from sliding drawers and panels to swipe-dismissable elements and buttons that stick to other elements as they move and animate.

Behavior对象是用来给CoordinatorLayout的子view们进行交互用的。从滑动,拉伸的布局修改,通过behavior来改变子view的动画效果。

Children of a CoordinatorLayout may have an anchor. This view id must correspond to an arbitrary descendant of the CoordinatorLayout, but it may not be the anchored child itself or a descendant of the anchored child. This can be used to place floating views relative to other arbitrary content panes.

CoordinatorLayout 还有一个layout_anchor 的属性,连同 layout_anchorGravity 一起可以用来放置与其他视图关联在一起的悬浮视图(如 FloatingActionButton)。

小结

Android Design Support Library用来实现Google的Material Design提供了一系列符合设计标准的控件。其中有众多的控件,其中最复杂,功能最强大的就是CoordinatorLayout, 它的神奇之处就在于Behavior对象作为了中介,实现触摸影响布局的形式产生动画效果。

功能

实现了多种Material Design中提到的滚动效果,如果自定义behavior,还能实现不同炫酷的效果。

例如:让浮动操作按钮上下滑动,为Snackbar留出空间

float_btn.gif

例如: 扩展或者缩小Toolbar或者头部,让主内容区域有更多的空间。

toolbar.gif

API官方地址:
https://developer.android.com/reference/android/support/design/widget/CoordinatorLayout.Behavior.html

英文单词学习:
specify 指定;详细说明;列举;把…列入说明书
interactions 交互,相互作用;相互交流(interaction复数)
annotation 注释;注解;释文
modifications 修改;修饰;变型;条款修订(modification的复数)
panels 面板(panel的复数);[建] 嵌板;事务委员会
anchor 锚;抛锚停泊;靠山;新闻节目主播
arbitrary 任意的;武断的;专制的
descendant 后裔;子孙
panes 玻璃

相关文章

网友评论

    本文标题:android CoordinatorLayout 控件介绍

    本文链接:https://www.haomeiwen.com/subject/xruzrttx.html