How to center multiple Views together using ConstraintLayout?

前端 未结 5 494
野的像风
野的像风 2021-02-01 12:17

Background

Google has announced a new layout called \"ConstraintLayout\" that\'s supposed to be the ultimate layout, that could replace all of the layouts while stayin

5条回答
  •  日久生厌
    2021-02-01 12:34

    Take a look at mine example (Center components in ConstraintLayout)

    For now you could center "image" (constrain left-top-bottom), constrain "label" top to "image" top, constrain "description" top to "label" bottom. In example below i have matched button height with two textviews to the right (which is your case). Other textviews are constrained as on the link above.

    UPDATE: Answering to your comment below:

    I have installed your app and this is only i can think of currently. Since it is a ViewHolder layout, layout_height can be set to wrap_content, or you can fix it if you'd like to. I can send you xml if you want, i dont want to flood the answer.

    Top TextView left constraint is constrained to right constraint of ImageView. Also, top TextView -> top constraint is constrained to top of container, so is right. Bottom TextView is constrained to bottom of container. TextViews in the middle are constrained to match width of top TextView and got no connection with ImageView.

提交回复
热议问题