What is difference between Barrier and Guideline in Constraint Layout?

前端 未结 2 1465
粉色の甜心
粉色の甜心 2020-12-07 10:51

Recently trying to implement Constraint Layout but I found Barrier and Guideline works same. Both works like divider.

2条回答
  •  囚心锁ツ
    2020-12-07 11:35

    When to use barriers

    Assume you have two TextView widgets with dynamic heights and you want to place a Button just below the tallest TextView:

    The ONLY way to implement that directly in the layout is to use a horizontal Barrier. That Barrier allows you to specify a constraint based on the height of those two TextViews. Then you constrain the top of your Button to the bottom of the horizontal Barrier.

    
    
    
        
    
        
    
        
    
        

    When to use guidelines

    Assume you want to restrict the above-mentioned TextView heights to 30% of screen height, no matter the content they have.

    To implement that you should add horizontal Guideline with percentage position and constrain the TextView bottom to that Guideline.

    
    
    
        
    
        
    
        

    Conclusion

    The only difference between Barrier and Guideline is that Barrier's position is flexible and always based on the size of multiple UI elements contained within it and Guideline's position is always fixed.

提交回复
热议问题