我在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>
任何人都可以阐明为什么会发生这种情况吗?
谢谢
编辑添加了通货膨胀代码
@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);
}
答案 0 :(得分:0)
@Cheticamp那真是个很酷的把戏,我不知道那个。这已经显示出一些人似乎指出的问题,我的片段被夸大为具有wrap_content高度的活动,因此被压缩了。现在一切正常。谢谢大家花费时间的帮助,在您仍在学习如何将片段和活动一起使用的同时,这似乎是一个相当容易解决的问题