Элементы макета не переходят на следующую строку - PullRequest
0 голосов
/ 28 июня 2019

Я пытаюсь воссоздать экран из приложения.Я использую пользовательский вид, который сочетает в себе вид изображения с 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>

two muppets

ОБНОВЛЕНИЕ:

Изменение свойства android: полосы прокрутки на вертикальное, казалось, решило проблему, но поместило только 1 изображение в каждой строке.

Ответы [ 2 ]

0 голосов
/ 02 июля 2019

Решено с помощью 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"/>

0 голосов
/ 02 июля 2019

Попробуйте с этим макетом

<?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>

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...