我设置了一个典型的回收器适配器。适配器中的某些项目有图像,有时只有一张图像,最多 12 个。我想显示图像,如下所示,具体取决于每个项目中的图像数量: 目前,我使用不同的布局文件来显示一组不同的图像。但问题是图像的大小不同,我只定义了 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/