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

问题描述 投票:1回答:1

Android上的约束布局出现一些奇怪的问题:

enter image description here

如您在上图中所看到的,下一个按钮位于屏幕的右下角(限制在父级的右下角)

但是,当我在手机上运行该应用程序时,结果如下:enter image description here

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

这里是整个布局:

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

谁能阐明为什么会这样吗?

谢谢

[Edit添加了通货膨胀代码

@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);
    }
android android-constraintlayout
1个回答
0
投票
@@ Cheticamp,那真是个很酷的把戏,我不知道那个。这已经显示出一些人指出的问题,我的片段被夸大为具有wrap_content高度的活动,因此被压缩了。现在一切正常。谢谢大家花费时间的帮助,在您仍在学习如何将片段和活动结合使用的同时,这似乎是一个相当容易解决的问题]
© www.soinside.com 2019 - 2024. All rights reserved.