Как исправить неправильное отображение изображения в FlexboxLayoutManager? - PullRequest
0 голосов
/ 20 октября 2019

У меня есть RecyclerView, в котором находится FlexboxLayoutManager. Моя проблема заключается в отображении изображений в FlexboxLayoutManager: image

Как вы можете видеть на изображении, есть пробелы, и я бы хотел FlexboxLayoutManager как-то адаптировать размер изображения

Элемент XML RecyclerView

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.v7.widget.CardView
        android:layout_marginStart="20dp"
        android:layout_marginTop="10dp"
        android:layout_marginEnd="20dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <android.support.v7.widget.RecyclerView
                app:layout_constraintTop_toTopOf="parent"
                android:id="@+id/rec_im"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
            <TextView
                app:layout_constraintTop_toBottomOf="@id/rec_im"
                android:layout_width="match_parent"
                android:id="@+id/text_post"
                android:layout_height="wrap_content"/>

            <TextView
                android:id="@+id/name_post"
                app:layout_constraintTop_toBottomOf="@id/text_post"
                android:layout_width="wrap_content"
                app:layout_constraintStart_toEndOf="@id/image_post"
                android:layout_height="wrap_content"/>
            <ImageView
                android:id="@+id/image_post"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/text_post"
                android:padding="10dp"
                android:layout_width="50dp"
                android:layout_height="50dp"/>
        </android.support.constraint.ConstraintLayout>

    </android.support.v7.widget.CardView>

</android.support.constraint.ConstraintLayout>

Адаптер

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val user = list[position]
        for (p in user) {
            holder.view.text_post.text = holder.view.text_post.text.toString() + p.text
        }
        mAdapter = Adapter()
        holder.view.rec_im.adapter = mAdapter
        val layoutManager = FlexboxLayoutManager(activity)
        layoutManager.flexWrap = WRAP
        layoutManager.flexDirection = ROW
        layoutManager.alignItems = STRETCH
        holder.view.rec_im.layoutManager = layoutManager
        mAdapter.update(activity, context, user)
    }

XML FlexboxLayoutManager RecyclerView

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <ImageView
        android:adjustViewBounds="true"
        android:layout_margin="5dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:id="@+id/image2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</android.support.constraint.ConstraintLayout>

Адаптер FlexboxLayoutManager RecyclerView

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val user = list[position]
        if (user.photo!= null && user.photo!="")
        Picasso.get().load(user.photo).into(holder.view.image2)
    }

Мне бы хотелось, чтобы результат был примерно таким: image

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