android - ConstraintLayout 忽略约束

标签 android android-constraintlayout

我有一个包含一些元素和两个按钮的 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>

View in editor

View when running

最佳答案

我能够通过使用设置为左/下/右边缘的垂直和水平准则来解决这个问题,并且我的控件正确地与这些准则对齐。

关于android - ConstraintLayout 忽略约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38150982/

相关文章:

Android、共享首选项和应用程序更新

java - 生成 java POCO 并通过读取 json 文件来填充它们,所有这些都是动态的

android - RecyclerView 适配器数据变化后如何确定最可见的 View 位置?

imageview - 在 ConstraintLayout 中有一个具有相同宽度和高度的 ImageView

android - 使用 match_parent 和 0dp 作为宽度时,具有 0dp 高度的 ConstraintLayout View 具有不同的实际高度

android - 无法为 "Galaxy Tab"制作全屏应用程序(Android 设备)

java - 我们可以使用 Firebase 的 UID 而不是注册 token 在 android 中发送通知吗?

android - 在 ConstraintLayout 中滚动浏览 RecyclerView 时如何折叠工具栏?

android - 约束布局在布局文件中不可见......并且在膨胀任何 View 时出现错误

android - ImageView 不以 ConstraintLayout 为中心