Отображение предметов рядом друг с другом - PullRequest
0 голосов
/ 27 января 2019

Я пытаюсь отобразить элементы в моем тестовом проекте, используя JSON и RecyclerView.Код работает нормально, но проблема в моем коде в том, что я вижу изображение построчно, а не рядом друг с другом.Я тоже пробовал Table Layout и Card Layout, но у меня это не сработало.Любой вклад высоко ценится.

Текущий показ

Image1
Image2
Image3
Image4
Image5

Ожидаемый результат

Image1 Image2 Image3
Image4 Image5

Полный код

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="3">
        <ImageView
        android:id="@+id/PersonImage"
        android:layout_width="113dp"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        android:contentDescription="@string/app_name"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.328"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@mipmap/ic_launcher" />
        <TextView
        android:id="@+id/PersonName"
        android:layout_width="71dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="80dp"
        android:layout_marginEnd="8dp"
        android:text="Name"
        android:textStyle="bold|italic"
        android:visibility="invisible"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/PersonImage"
        app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>

1 Ответ

0 голосов
/ 27 января 2019

Измените корень линейный layout_width на wrap_content.Затем, когда вы устанавливаете переработчик, измените макет менеджера на GridLayoutManager, например:

int columnSize = 3;
mLayoutManager = new GridLayoutManager(this, columnSize);
mRecyclerView.setLayoutManager(mLayoutManager);

Ссылка на документ

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