ConstraintLayout居中
时间: 2023-10-23 10:10:05 浏览: 92
要在 ConstraintLayout 中居中视图,您可以使用以下方法之一:
1. 水平和垂直居中:使用以下属性将视图水平和垂直居中:
```xml
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
```
2. 水平居中:使用以下属性将视图水平居中:
```xml
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
```
3. 垂直居中:使用以下属性将视图垂直居中:
```xml
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
```
4. 在父布局的中心居中:使用以下属性将视图在父布局的中心居中:
```xml
app:layout_constraintCircle="@+id/parent_id"
app:layout_constraintCircleRadius="0dp"
app:layout_constraintCircleAngle="0"
```
其中,`parent_id` 是指父布局的 ID。
阅读全文
相关推荐


















