带有约束布局的ScrollView(顶部为空白)

时间:2020-08-29 16:34:49

标签: android scrollview android-constraintlayout

我一直使用ScrollView作为父级,使用Constraint Layout作为子级。约束子项布局在其父项的顶部和底部之间绑定(让我们说 View 1 )。

当我添加另一个TextView( View 2 )时,其边界为50宽度,wrap_content为高度。现在,如果我添加Long文本值,则 View 1 “查看2” 开始下降,如果我增加文字量,它开始显示在屏幕外。

任何对此的解决方案

<ScrollView 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:id="@+id/scroller"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="true"
    android:clipToPadding="true"
    android:descendantFocusability="beforeDescendants"
    android:fillViewport="true"
    android:focusableInTouchMode="true"
    android:scrollbars="vertical"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    tools:context=".MainActivity">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/line1"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:text="Hello Wosaddsadasrld!"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/line2"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:text="Hello Wosaddsadajhsf
            iabdjkjasbdjsjabdsajbjahsbdjabshjdsajbs
            ajbjhbdsjabshbdbhjbasjhbhadjbjhabsjadbjdbs
            ajbdbashbbasdbhdbashjbjkvdsbkjvdbsjkbdsvsrld!"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@id/line1" />

        <TextView
            android:id="@+id/line3"
            android:layout_width="50dp"
            android:layout_height="0dp"
            android:gravity="center"
            android:text="Bagadehs"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@id/line2" />

        <TextView
            android:id="@+id/line4"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="sdfdsf"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@id/line3" />

        <TextView
            android:id="@+id/line5"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="rtte"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@id/line4" />

    </androidx.constraintlayout.widget.ConstraintLayout>

</ScrollView>

Kindly see the Scroll bars enter image description here

0 个答案:

没有答案