如何在约束布局1.1中使用新功能? [英] How to use new features in constraint layout 1.1?

查看:82
本文介绍了如何在约束布局1.1中使用新功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何在约束布局1.1中使用新功能,即障碍物和基于百分比的尺寸吗?网上绝对没有可用的文档,最近的Google I/O关于设计器工具的演讲仅详细讨论了占位符.顺便说一句,我发现了如何使用组,这也是一个新功能.您只需添加

Does anyone know how to use new features in constraint layout 1.1, namely barriers and percent-based dimensions? There is absolutely no documentation available online, and the recent Google I/O talk on designer tools covered in detail only placeholders. BTW, I found out how to use groups, which are also a new feature. You need to simply add

<android.support.constraint.Group
    app:constraint_referenced_ids="button1, button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

到约束布局,其中app:constraint_referenced_ids是一个字符串,您应在其中枚举要与该组关联的视图的逗号分隔ID.现在,切换组的可见性会更改该组引用的所有视图的可见性,我认为这是此功能的主要目的.

to your constraint layout, where app:constraint_referenced_ids is a string, where you should enumerate comma separated ids of views, that you want to be associated with this group. Now, toggling the visibility of a group changes the visibility of all the views referenced by it, which I think is the main purpose of this feature right now.

推荐答案

更新:

Update: An official release of Constraint Layout 1.1.0 is finally here, complete with official documentation!

文档非常稀缺第一次问这个问题的时候.我能找到的最好的地方是此Reddit帖子!但是那里的信息给了我足够的提示,可以创建一个带有水平障碍的约束布局.它确实有效,并且新的(beta)约束布局还解决了wrap_content的一些不良问题.我对约束布局"测试版的第一印象非常积极,这在许多其他测试中都没有得到解决.

Documentation of the new features was very scarce when this question was first asked. The best that I could find was in this Reddit post! But the information there gave me enough hints to create a constraint layout with a horizontal barrier in it. It actually worked, and the new (beta) constraint layout also fixed some bad problems with wrap_content. My very positive first impression of the Constraint Layout Beta has held up under lots of additional testing.

在使用新内容之前,将ConstraintLayout 1.1.0添加到项目中.

Before using the new stuff, add ConstraintLayout 1.1.0 to the project.

app/build.gradle 中,将约束布局依赖项更改为此:

In app/build.gradle, change the constraint layout dependency to this:

implementation 'com.android.support.constraint:constraint-layout:1.1.0'

您可能还需要将Maven存储库添加到项目的build.gradle (项目根目录中的另一个文件)中.查找 allprojects存储库部分,并添加以下内容:maven { url 'https://maven.google.com' }因此,整个部分应如下所示:

You might also need to add the maven repository to your project's build.gradle (which is a different file, in your project's root directory). Look for the allprojects repositories section and add this: maven { url 'https://maven.google.com' } So the whole section should look something like this:

allprojects {
     repositories {
         jcenter()
         maven { url 'https://maven.google.com' }
     }
}

现在是有趣的东西了!以下代码段创建了水平障碍,因此bottom_textview低于included_layoutmultiline_textview.

Now for the fun stuff! The following snippet creates a horizontal barrier, so that bottom_textview is below both included_layout and multiline_textview.

<android.support.constraint.Barrier
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/barrier1"
    app:barrierDirection="bottom"
    app:constraint_referenced_ids="included_layout, multiline_textview" />

<TextView
    android:id="@+id/bottom_textview"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/barrier1"
    android:layout_width="0dp"
    android:layout_height="wrap_content" />

第一印象:障碍很大!我的新布局更平坦,更简单,并且似乎仍然可以完全满足我的要求.绝对值得尝试.

First impression: Barriers are great! My new layout is flatter and simpler, and still seems to do exactly what I want. It's definitely worth trying.

更多详细文档逐渐可用:

More detailed documentation is gradually becoming available:

关于圆形定位的出色文章,并附有动画

关于障碍的精美文章,位于 有关在medium.com上添加了新的1.1.x小部件(包括大量详细信息和示例代码)

来自androidtkt.com的文章,其中包含障碍,组,占位符和百分比尺寸的示例

@Vyacheslav A 的答案也很好地总结了新功能的作用.

@Vyacheslav A's answer also has a great summary of what the new features can do.

这篇关于如何在约束布局1.1中使用新功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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