Android 布局元素不会转到下一行

Android 布局元素不会转到下一行,android,layout,Android,Layout,我正在尝试从应用程序重新创建屏幕。我使用的是一个自定义视图,它将一个图像视图与3个文本视图相结合。然后,我将这些自定义视图插入到滚动视图的线性布局中,但是我只能看到其中两个,其余的则看不到图片 主要活动的XML: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/a

我正在尝试从应用程序重新创建屏幕。我使用的是一个自定义视图,它将一个图像视图与3个文本视图相结合。然后,我将这些自定义视图插入到滚动视图的线性布局中,但是我只能看到其中两个,其余的则看不到图片

主要活动的XML:

<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MainActivity">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clipToPadding="false"
    android:paddingStart="16sp"
    android:scrollbars="none"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="12sp"
        android:orientation="horizontal">

        <com.example.knigoteka.BenefitView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="12dp"
            app:image="@drawable/jesus"
            app:textCaption="Apply and chat with our hosts"
            app:textAutor = "Vasko Vasilev"
            app:textPrice="420 ДЕН"/>

        <com.example.knigoteka.BenefitView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="12dp"
            app:image="@drawable/jesus"
            app:textAutor = "Vasko Vasilev"
            app:textCaption="Boze Boze"
            app:textPrice="420 ДЕН"/>

        <com.example.knigoteka.BenefitView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="12dp"
            app:image="@drawable/jesus"
            app:textCaption="Apply and chat with our hosts"
            app:textAutor = "Vasko Vasilev"
            app:textPrice="420 ДЕН"/>

        <com.example.knigoteka.BenefitView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="12dp"
            app:image="@drawable/jesus"
            app:textCaption="Apply and chat with our hosts"
            app:textAutor = "Vasko Vasilev"
            app:textPrice="420 ДЕН"/>

    </LinearLayout>
    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>
更新:

将android:scrollbars属性更改为vertical似乎可以解决这个问题,但每行仅放置一个图像。

尝试使用此布局

<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MainActivity">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clipToPadding="false"
    android:paddingStart="16sp"
    android:scrollbars="none"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">
<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="12sp"
        android:orientation="vertical">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="12sp"
        android:orientation="horizontal">

        <com.example.knigoteka.BenefitView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="12dp"
            app:image="@drawable/jesus"
            app:textCaption="Apply and chat with our hosts"
            app:textAutor = "Vasko Vasilev"
            app:textPrice="420 ДЕН"/>

        <com.example.knigoteka.BenefitView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="12dp"
            app:image="@drawable/jesus"
            app:textAutor = "Vasko Vasilev"
            app:textCaption="Boze Boze"
            app:textPrice="420 ДЕН"/>
</LinearLayout>

  <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="12sp"
        android:orientation="horizontal">

        <com.example.knigoteka.BenefitView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="12dp"
            app:image="@drawable/jesus"
            app:textCaption="Apply and chat with our hosts"
            app:textAutor = "Vasko Vasilev"
            app:textPrice="420 ДЕН"/>

        <com.example.knigoteka.BenefitView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="12dp"
            app:image="@drawable/jesus"
            app:textCaption="Apply and chat with our hosts"
            app:textAutor = "Vasko Vasilev"
            app:textPrice="420 ДЕН"/>
</LinearLayout>
    </LinearLayout>
    </ScrollView>

通过使用RecyclerView和自定义布局解决。 自定义布局xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="370px"
android:layout_height="740px"
android:gravity="center"
android:padding="1dp"
android:layout_margin="30dp"
android:background="#000000"
android:id="@+id/parent_layout">


<ImageView
    android:id="@+id/image"
    android:layout_width="match_parent"
    android:layout_height="190dp"
     android:layout_marginBottom="2dp"
    tools:src="@color/colorPrimary"
    android:background="#010101"/>



<TextView
    android:id="@+id/caption"
    android:textStyle="bold"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:text="Caption of the Book"
    android:textAlignment="viewStart"
    android:textColor="#666"
    android:textSize="12sp"
    android:singleLine="true"
    android:background="#FFFFFF"
    android:paddingLeft="5dp"
    android:layout_below="@+id/image"/>

<TextView
    android:id="@+id/autor"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:text="Caption of the Book"
    android:textAlignment="viewStart"
    android:textColor="#666"
    android:textSize="12sp"
    android:singleLine="true"
    android:background="#FFFFFF"
    android:paddingLeft="5dp"
    android:layout_below="@+id/caption"/>

<View
    android:id="@+id/line"
    android:layout_width="16dp"
    android:layout_height="1dp"
    android:layout_gravity="center"
    android:layout_below="@+id/autor"
    android:background="#000000" />

<TextView
    android:id="@+id/price"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:text="Price of the Book"
    android:textAlignment="viewEnd"
    android:textColor="#666"
    android:textSize="12sp"
    android:paddingBottom="1dp"
    android:singleLine="true"
    android:background="#FFFFFF"
    android:paddingRight="5dp"
    android:layout_below="@+id/line"/>

为ScrollView添加android:fillViewPort=true。不起作用:/LinearLayout的预期行为。它不起作用,因为LinearLayout没有包装功能。你有几个选择。1手动将视图逐行放置在所需位置。2.RecyclerView@glucaio这是对的。线性布局不能做你想做的。还有第三种选择: