TL;DR
The view width must be exactly half of the screen, and be centered. Using ConstraintLayout
.
Note that the view does not have any inner width.
<View android:background="#ff0000" ... />
Original question
I would like to achieve a layout where a view size is half the screen size, and centered horizontally.
Something like this: |--view--|
I can't find any way using ConstraintLayout. The best i found is by using app:layout_constraintHorizontal_weight="1"
on 2 fake views positioned at the full left and full right respectively, and app:layout_constraintHorizontal_weight="1.5"
on my view.
Any better way ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…