安卓6上的ConstraintLayout问题

3

我发现在我的项目中使用ConstraintLayout时出现了一个非常奇怪的bug。实际上,这个问题只存在于Android 6上。

我正在使用以下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:fitsSystemWindows="true"
tools:context="com.fagets.rainbowsixapp.login.LoginStepOneFragment">

<LinearLayout
    android:id="@+id/linearLayout_login_form"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    tools:layout_constraintRight_creator="1"
    tools:layout_constraintBottom_creator="1"
    android:layout_marginStart="65dp"
    app:layout_constraintBottom_toBottomOf="parent"
    android:layout_marginEnd="65dp"
    app:layout_constraintRight_toRightOf="parent"
    tools:layout_constraintLeft_creator="1"
    android:layout_marginBottom="18dp"
    app:layout_constraintLeft_toLeftOf="parent"
    android:layout_marginLeft="65dp"
    android:layout_marginRight="65dp">

    <com.facebook.login.widget.LoginButton
        xmlns:facebook="http://schemas.android.com/apk/res-auto"
        android:id="@+id/login_button_facebook"
        style="@style/LoginButton"
        android:paddingTop="15dp"
        android:paddingBottom="15dp"
        facebook:com_facebook_login_text="@string/login_connect_facebook"/>

    <Button
        android:id="@+id/login_button_google"
        style="@style/LoginButton"
        android:textColor="@color/login_button_google_text"
        android:background="@drawable/login_button_shape_google"
        android:text="@string/login_connect_google"/>

    <Button
        android:id="@+id/login_button_anonymous"
        style="@style/LoginButton"
        android:background="@drawable/login_button_shape_anonymous"
        android:text="@string/login_connect_anonymous"/>

    <Button
        android:id="@+id/login_button_about"
        style="@style/LoginButton"
        android:background="@android:color/transparent"
        android:text="@string/login_connect_about"
        android:textColor="@color/login_button_google_text"/>

</LinearLayout>

我的问题涉及LinearLayout中的app:layout_constraintBottom_toBottomOf="parent"。在Android 6上,LinearLayout被裁剪而不是粘在底部。它在Android 7上正常工作,甚至在Android 4.4.2上也是如此。之后,我尝试删除LinearLayout,只使用ConstraintLayout,但仍然存在相同的问题。
以下是Android 7的屏幕截图: enter image description here 以下是Android 6的问题: enter image description here 我做错了什么吗?还是这是ConstraintLayout库的问题?
谢谢!
1个回答

0

当您使用约束布局时,不需要额外的LinearLayout

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">

    <Button
        android:id="@+id/button1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginBottom="16dp"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent" />

    <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        android:layout_marginBottom="16dp"
        app:layout_constraintBottom_toTopOf="@+id/button1" />

    <Button
        android:id="@+id/button3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        android:layout_marginBottom="16dp"
        app:layout_constraintBottom_toTopOf="@+id/button2" />

</android.support.constraint.ConstraintLayout> 

enter image description here


如果你已经阅读了我所有的出版物,你会发现我已经尝试过那个解决方案。但是我仍然面临着同样的问题。 - Guimareshh
嗯...我在Android-6设备上编译了这个XML文件,它对我有效。我不认为这是ConstraintLayout的问题...然而,这是我的ConstraintLayout版本...com.android.support.constraint:constraint-layout:1.0.2 - S Haque
我正在使用与您相同的版本,用于ConstraintLayout。此外,我复制并粘贴了您的代码,即使在Android 6上运行它后,问题仍然存在(在Nexus 5和Sony Xperia Z3 Compact上进行测试)。 - Guimareshh
这很奇怪...我在Nexus 5上运行了它...如果我有任何发现,我会让你知道的。 - S Haque
1
这里有任何更新吗?我在Android 6.0.1上也遇到了constraintlayout的问题。 - John Ernest Guadalupe

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接