【发布时间】:2019-08-31 20:38:54
【问题描述】:
我正在尝试将两个视图一个接一个地对齐,垂直和水平居中。 视图的大小动态设置为屏幕的大小,这是屏幕的 XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/yellow"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#faff68"
app:layout_constraintHeight_default="percent"
app:layout_constraintHeight_percent="0.6"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintBottom_toBottomOf="@id/purple"
app:layout_constraintLeft_toLeftOf="@id/purple"
app:layout_constraintRight_toRightOf="@id/purple"
app:layout_constraintTop_toTopOf="@id/purple" />
<ImageView
android:id="@+id/purple"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#c303fa"
app:layout_constraintHeight_default="percent"
app:layout_constraintHeight_percent="0.5"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
如何使用约束布局将黄色图像置于紫色图像的中心? (我知道如何在其他布局中实现)
【问题讨论】:
-
我已经更新了我的答案,以展示如何使用 Circular Positioning 来实现你想要的。请检查一下,干杯。
标签: android android-layout android-constraintlayout