Align ConstraintLayout item to be at the end of two items

前端 未结 2 1328
萌比男神i
萌比男神i 2021-02-13 06:02

I have a ConstraintLayout with two views A and B that are stacked vertically. I have a third view C which needs to be to the end of both A and B horizontally. At any given point

2条回答
  •  爱一瞬间的悲伤
    2021-02-13 06:24

    This can be easily achieved using the new Barriers feature.

    
    
    
        
    
        
    
        
    
        
    
    
    

    How to use Barriers ?

    Barriers are like building a HUUUUGE WALL that "protects" the views mentioned in constraint_referenced_ids. So, you have to mention which direction it's "supposed to keep out" which in our case is the right (view_c). Just use the barrierDirection attribute.
    Finally, don't forget to make sure that view_c is in the keep out zone (layout_constraintLeft_toRightOf="@+id/barrier1").

    As this feature is available only in the 1.1.0 beta1 release of ConstraintLayout, don't forget to add this line to your build.gradle file.

    compile 'com.android.support.constraint:constraint-layout:1.1.0-beta1'
    


    Hope this helps!

提交回复
热议问题