android - 在回收 View 中显示不同尺寸的多个图像

标签 android android-layout android-recyclerview android-imageview

我设置了一个典型的回收器适配器。适配器中的某些项目有图像,有时只有一张图像,最多 12 个。我想显示图像,如下所示,具体取决于每个项目中的图像数量: Real Image Sample sizes 目前,我使用不同的布局文件来显示一组不同的图像。但问题是图像的大小不同,我只定义了 4 个图像集,我使用 GLIDE 库来显示图像。

如果图像为 4,它们将调整为更大的图像尺寸的代码

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="3"
    android:minHeight="@dimen/dp_200"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/image4"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:contentDescription="@string/content_desc"
        android:scaleType="fitXY" />

    <ImageView
        android:id="@+id/image5"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:contentDescription="@string/content_desc"
        android:scaleType="fitXY" />

    <ImageView
        android:id="@+id/image6"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:contentDescription="@string/content_desc"
        android:scaleType="fitXY" />

</LinearLayout>

我正在寻找任何应与 Target API 29 配合使用的可用库。以前的解决方案不适用于较新的 Target API。

最佳答案

我认为你可以使用flexboxlayoutmanager,你可以查看示例here

关于android - 在回收 View 中显示不同尺寸的多个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61493260/

相关文章:

android - 如何在 Constraint Layout 中同时应用左约束和右约束时将布局左对齐?

php - 如何从 Android 向 Web 服务器发送数据

android - 是否可以实现这样的 Activity 行为?

android - toEndOf 在自定义对话框布局中不起作用

android - 单击怪异的声音循环

android - 在 Android 中重新创建后 RecyclerView 不显示任何内容

android - 在Android Studio应用程序上添加声音

android - WindowSoftInputMode 和 ScrollView

android - RecyclerView.OnScrollListener (dy,dx) 的单位是什么?

android - SwipeRefreshLayout 内的 RecyclerView 不显示