这个布局将显示一个带有一种颜色的视图和另一个带有另一种颜色的视图。
当layout_constraintWidth_percent = 1时,这两个视图宽度相同。当我将它设置在0.92<> 1之间时,前景视图变得比背景视图更大。
有谁可以解决这个问题吗?我需要前景视图占背景视图的x百分比。
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="15dp"
android:paddingBottom="15dp"
>
<View
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:background="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<View
android:id="@+id/foreground"
android:layout_width="0dp"
android:layout_height="80dp"
android:background="@color/colorAccent"
app:layout_constraintWidth_percent="0.94"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintBottom_toBottomOf="@id/background"
app:layout_constraintLeft_toLeftOf="@id/background"
app:layout_constraintRight_toRightOf="@id/background"
app:layout_constraintTop_toTopOf="@id/background"
/>
</android.support.constraint.ConstraintLayout>