我有一个包含一些元素和两个按钮的 ConstraintLayout
。
我试图通过使用顶部和底部约束并使用 bias 属性获得底部/左/右对齐来将按钮放在底部。
一切都在编辑器中正确显示 (Android studio 2.2 P3
),但是当我运行应用程序时,没有任何正确显示。
如有任何帮助,我们将不胜感激。
这是layout XML
的相关部分
<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"
android:id="@+id/relativeLayout"
android:paddingTop="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp">
...snip...
<Button
android:text="Reset"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_constraintLeft_toLeftOf="@+id/relativeLayout"
app:layout_constraintBottom_toBottomOf="@+id/relativeLayout"
android:layout_marginBottom="16dp" />
<Button
android:text="Apply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/profile_apply_button"
app:layout_constraintLeft_toLeftOf="@+id/relativeLayout"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
app:layout_constraintTop_toTopOf="@+id/relativeLayout"
android:layout_marginTop="16dp"
app:layout_constraintRight_toRightOf="@+id/relativeLayout"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintBottom_toBottomOf="@+id/relativeLayout"
android:layout_marginBottom="16dp"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintVertical_bias="1.0" />
</android.support.constraint.ConstraintLayout>
最佳答案
我能够通过使用设置为左/下/右边缘的垂直和水平准则来解决这个问题,并且我的控件正确地与这些准则对齐。
关于android - ConstraintLayout 忽略约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38150982/