ConstraintLayout with Barriers; How to constraint to bottom / top of barrier depending on size

后端 未结 2 2102
难免孤独
难免孤独 2021-01-03 09:55

I am trying out the new Barrier feature in the 1.1.0-beta1. It works as expected however there is this use-case I cant seem to figure or (or is possible ConstraintLayout at

2条回答
  •  梦毁少年i
    2021-01-03 10:23

    @Cheticamp 's answer is great, but he doesn't explain how he came up that idea.

    Here is how I came up another solution inspired by his solution.

    What we want to achieve is to put the button as high as possible, but it should be constrained to two limits:

    1. button.bottom >= image.bottom

    2. button.top >= text.bottom

    We can use Barrier to satisfy these two requirements, but we need to modify one of them, I choose to modify the second one:

    button.top >= text.bottom <=> button.bottom >= text.bottom + button.height

    Now we have these two constraints:

    1. button.bottom >= image.bottom

    2. button.bottom >= text.bottom + button.height

    Now we can place a fake button below the TextView like this:

    
    
    
    
        
    
        
    
        
    
        

提交回复
热议问题