小编Far*_*rid的帖子

ScrollView 在约束布局内不起作用

我在 ConstraintLayout 中有一个滚动视图。但滚动视图在 ConstraintLayout 中不起作用。我尝试使用 NestedScrollView 而不是 ScrollView,但它仍然不起作用。ScrollView 在 LinearLayout 或relativelayout 中工作得很好,但在 ConstraintLayout 中不起作用。我将 android:layout_height 更改为 match_parent 和 wrap_content 但它不起作用。问题是什么?

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

    <include
        android:id="@+id/other_toolbar_xml"
        layout="@layout/other_toolbar_xml"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintTop_toBottomOf="@id/other_toolbar_xml"
        android:fillViewport="true"
        tools:ignore="MissingConstraints"
        >

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

            <ImageView
                android:id="@+id/img_content_xml"
                android:layout_width="match_parent"
                android:layout_height="170dp"
                app:layout_constraintTop_toBottomOf="@id/other_toolbar_xml"
                android:scaleType="fitXY"
                tools:ignore="NotSibling"
                />

            <TextView
                android:id="@+id/title_content_xml"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@id/img_content_xml"
                android:layout_marginRight="16dp"
                android:paddingLeft="16dp"
                android:textDirection="rtl"
                android:text="title"
                android:textSize="17sp"
                android:textColor="#1d1d1d"
                />

            <TextView
                android:id="@+id/content_content_xml"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@id/title_content_xml"
                android:layout_marginTop="20dp"
                android:layout_marginRight="16dp"
                android:layout_marginEnd="16dp"
                android:paddingLeft="16dp"
                android:textDirection="rtl"
                android:text="content"
                android:textColor="#1d1d1d"
                /> …
Run Code Online (Sandbox Code Playgroud)

android android-scrollview android-constraintlayout

4
推荐指数
1
解决办法
8562
查看次数