所以我将这段代码保存在一个XML文件中:

<androidx.constraintlayout.widget.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">

    <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="500dp"
            android:id="@+id/constraintLayout" app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/text_dashboard">
        <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/scrollView2">
            <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"
                            android:orientation="vertical">
                <TextView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:id="@+id/textView" android:text="@string/Tester" android:layout_alignParentEnd="true"
                        android:layout_marginEnd="18dp" android:layout_marginStart="10dp"
                        android:layout_alignParentBottom="true"
                        android:layout_marginBottom="50dp" android:layout_margin="0dp"/>
            </RelativeLayout>
        </ScrollView>
    </androidx.constraintlayout.widget.ConstraintLayout>


文本视图中的底部边距将添加到顶部,而不是底部,并且滚动视图底部的文本被切除。另外,当我尝试仅移动布局时,如果将其向下拖动,则释放后它将向上移动,反之亦然。有人知道这里发生了什么吗?

最佳答案

<androidx.constraintlayout.widget.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">
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    tools:ignore="MissingConstraints"
    android:orientation="vertical"
    >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/textView"
                android:text="Tester"
                android:layout_marginEnd="18dp" android:layout_marginStart="10dp"
                android:layout_marginBottom="50dp" android:layout_margin="0dp"/>
</LinearLayout>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/scrollView2">
    </ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

07-27 16:16