Android - Align view center to bottom of other view

后端 未结 7 1067
小蘑菇
小蘑菇 2020-12-31 00:57

A picture tells more than a lengthy speech :

I want to align vertically the center of the red part with the middle of the black part. I have no constraint of contai

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-31 01:34

    This is also possible using the ConstraintLayout. Similar to how aligning the start/end of a view to the parent centers it within the parent, we can use that concept to center along the edge of a View.

    The key to this layout is two constraints on our bottom view:

    app:layout_constraintTop_toBottomOf="@id/top_view"
    app:layout_constraintBottom_toBottomOf="@id/top_view"
    

    By constraining both the top/bottom of the lower view to the bottom of the upper view, the layout will adjust to center it along that bottom. Here is the full code and screenshot of the blueprint:

    
    
    
        
    
        
    
    
    

提交回复
热议问题