尊重限制我试图把一个ConstraintLayout内的CardView,对双方一定的余量。CardView在Android不从ConstraintLayout
我设置CardView利润率相比,父母,左,右,然后设置layout_width在0dp:它会延长,并采取一切可用的空间,忽略了利润率。
如果我将CardView放入FrameLayout中,然后将相同的确切约束应用于FrameLayout,则FrameLayout将尊重它们,并且CardView将适合它(请参阅下面的代码)。
<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="...MyActivity...">
<FrameLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="32dp"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:layout_marginStart="32dp"
android:layout_marginTop="32dp"
app:layout_constraintBottom_toTopOf="@+id/nextButton"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.v7.widget.CardView>
<...omitted...>
所以我得到它的工作我需要的方式,但我想明白为什么计算自己的宽度,设置为0dp时CardView不走的利润考虑在内。
不会只改变编辑器内的位置吗?这是我对“工具”命名空间的理解 – gianpi
我编辑了我的文章,因为我不得不添加一些东西,它的工作原理。 – Meikiem
检查一下,我测试了它,左右边距保持不变 – Meikiem