ConstraintLayout, when constraint dependent view is gone, the layout view behave weirdly

后端 未结 4 501
执念已碎
执念已碎 2020-12-16 09:18

I\'m using ConstraintLayout where I will show as below

I would like to hide First (using gone), and which the view I expect to be as below (whe

4条回答
  •  自闭症患者
    2020-12-16 09:40

    An answer has already been given linking to Barriers. I will provide an example of how I've actually implemented it:

    
    
    
    
    

    This example shows 2 TextViews either of which can be gone. The Views are on stacked from top to bottom, so barrierDirection is set to bottom. Should you need another direction, just change that line accordingly.

    Setting any of the 2 TextViews to gone, will result in the Barrier shifting to the bottom of the other, and if we set both to gone, it'll just shift up to the element that textView1's top constraint was referencing, in this case, the parent.

    Note: If your textView1's top constraint is something else, i.e. it's below another element, the barrier will end up there if both views are set to gone.

提交回复
热议问题