ConstraintLayout: how to have a view be half the screen width and centered?

后端 未结 5 1209
半阙折子戏
半阙折子戏 2020-12-16 09:49

TL;DR
The view width must be exactly half of the screen, and be centered. Using ConstraintLayout.

Note that the view does not have

5条回答
  •  醉话见心
    2020-12-16 10:16

    As of** ConstraintLayout1.1.0-beta1**, you can use percent to define widths & heights.

    android:layout_width="0dp"
    app:layout_constraintWidth_default="percent"
    app:layout_constraintWidth_percent=".4"
    

    This will define the width to be 40% of the width of the screen. A combination of this and guidelines in percent allow you to create any percent based layout you want.

提交回复
热议问题