How to use new features in constraint layout 1.1?

前端 未结 4 612
忘掉有多难
忘掉有多难 2020-12-28 15:56

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 t

4条回答
  •  暖寄归人
    2020-12-28 16:41

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


    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.

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

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

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

    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' }
         }
    }
    

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

    
    
    
    

    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:

    • summary of the new features in 1.1.0

    • an excellent article about circular positioning, complete with animation

    • a nice detailed article about barriers at constraintlayout.com (!)

    • an article about the new 1.1.x widgets (including lots of details and sample code) at medium.com

    • an article from androidtkt.com with examples of barriers, groups, placeholders, and percent dimensions

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

提交回复
热议问题