Android约束布局按钮浮动到顶部

Android约束布局按钮浮动到顶部,android,android-constraintlayout,Android,Android Constraintlayout,我对Android上的约束布局有一些奇怪的问题: 如上图所示,“下一步”按钮位于屏幕的右下角(它被限制在父项的右侧和底部) 但是,当我在手机上运行应用程序时,结果是: 由于某种原因,按钮会浮动到屏幕顶部 以下是整个布局: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:app="http://schemas.android.com

我对Android上的约束布局有一些奇怪的问题:

如上图所示,“下一步”按钮位于屏幕的右下角(它被限制在父项的右侧和底部)

但是,当我在手机上运行应用程序时,结果是:

由于某种原因,按钮会浮动到屏幕顶部

以下是整个布局:

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <TextView
        android:id="@+id/textView6"
        style="@style/headerText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:text="Enter Your Name"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="24dp"
        android:layout_marginEnd="16dp"
        android:text="blah blah blah"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="@+id/textView6"
        app:layout_constraintTop_toBottomOf="@+id/textView6" />

    <Button
        android:id="@+id/btnNext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="32dp"
        android:layout_marginBottom="32dp"
        android:text="Next"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

@切蒂卡普:这真是一个很酷的把戏,我不知道那一个。这表明了一个问题,正如一些人所指出的,我的片段被膨胀成一个活动,内容高度为wrap_,所以它被压扁了。现在一切都好了。感谢大家花时间提供帮助,当您还在学习如何将片段和活动一起使用时,这感觉是一个相当容易解决的问题。

@Cheticamp这是一个非常酷的技巧,我不知道这个。这表明了一个问题,正如一些人所指出的,我的片段被膨胀成一个活动,内容高度为wrap_,所以它被压扁了。现在一切都好了。感谢大家花时间提供帮助,在您仍在学习如何将片段和活动一起使用时,这感觉是一个相当容易解决的问题

检查您的约束布局依赖关系是否最新,如何扩大布局?可能是由于某些原因,ConstraintLayout没有填满整个屏幕。我已经检查了您的代码,它在我这边运行良好。从我这边运行良好,您可以清除并重建应用程序,如果它不工作。检查布局检查器以查看ConstraintLayout的真实大小。工具->布局检查器,然后选择您的应用程序。看起来ConstraintLayout的父级正在约束其大小。布局检查器将显示一些信息。检查您的约束布局依赖项是否为最新的。如何放大布局?可能是由于某些原因,ConstraintLayout没有填满整个屏幕。我已经检查了您的代码,它在我这边运行良好。从我这边运行良好,您可以清除并重建应用程序,如果它不工作。检查布局检查器以查看ConstraintLayout的真实大小。工具->布局检查器,然后选择您的应用程序。看起来ConstraintLayout的父级正在约束其大小。布局检查员将提供一些信息。很高兴这有帮助。布局检查器是每个人都应该利用的“公开”秘密之一。很高兴它有帮助。布局检查器是每个人都应该利用的“公开”秘密之一。
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_user_name, container, false);
    }