我发现在我的项目中使用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](https://istack.dev59.com/WICPu.webp)
![enter image description here](https://istack.dev59.com/N0vQM.webp)
谢谢!