在 ScrollView 中带有文本的多图像视图

Multiples imagesView with text in a ScrollView

我正在 android 工作室为我和我的朋友制作音箱。 我有一个简单的滚动视图,我用多个 constraintLayout 填充了它,每个 constraintLayout 包含 2 个 imageView,每个 imageView 下面都有一行文本。

问题是,当我 运行 应用程序时,我只看到 2 个第一个布局,我不知道发生了什么,这可能不是好的方法。

最好的解决方案是什么?这是 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:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="800dp"
    android:background="#353535"
    tools:context=".MainActivity">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <Button
                android:id="@+id/buttonStopAll"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@color/red_perso"
                android:text="Stop tout"
                android:textColor="#000000" />

            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/constraintLayout"
                android:layout_width="match_parent"
                android:layout_height="200dp">

                <ImageView
                    android:id="@+id/idTheoGonfle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:srcCompat="@drawable/theosouffle" />

                <ImageView
                    android:id="@+id/idChuteCJ"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:srcCompat="@drawable/cjchute" />

                <TextView
                    android:id="@+id/textTheoGonfle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:width="150dp"
                    android:background="#FFEB3B"
                    android:fontFamily="sans-serif-black"
                    android:gravity="center"
                    android:text="Théo gonfle"
                    android:textAllCaps="false"
                    android:textColor="#000000"
                    android:textSize="16sp"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/idTheoGonfle" />

                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:width="150dp"
                    android:background="#FFEB3B"
                    android:fontFamily="sans-serif-black"
                    android:text="TextView"
                    android:textAlignment="center"
                    android:textColor="#000000"
                    android:textSize="16sp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/idChuteCJ" />

            </androidx.constraintlayout.widget.ConstraintLayout>

            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/constraintLayout4"
                android:layout_width="match_parent"
                android:layout_height="200dp">


                <ImageView
                    android:id="@+id/imageView7"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:srcCompat="@drawable/ic_launcher_foreground" />

                <ImageView
                    android:id="@+id/imageView8"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:srcCompat="@drawable/ic_launcher_foreground" />
            </androidx.constraintlayout.widget.ConstraintLayout>

            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/constraintLayout3"
                android:layout_width="match_parent"
                android:layout_height="200dp">


                <ImageView
                    android:id="@+id/imageView9"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    tools:srcCompat="@tools:sample/avatars" />

                <ImageView
                    android:id="@+id/imageView10"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    tools:srcCompat="@tools:sample/avatars" />
            </androidx.constraintlayout.widget.ConstraintLayout>

            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/constraintLayout2"
                android:layout_width="match_parent"
                android:layout_height="200dp">


                <ImageView
                    android:id="@+id/imageView11"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    tools:srcCompat="@tools:sample/avatars" />

                <ImageView
                    android:id="@+id/imageView12"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    tools:srcCompat="@tools:sample/avatars" />
            </androidx.constraintlayout.widget.ConstraintLayout>

        </LinearLayout>
    </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:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="800dp"
android:background="#353535"
tools:context=".MainActivity">

看起来像你的问题 android:layout_height="800dp" 您设置固定高度。将其更改为 match_parent。