【发布时间】:2016-10-17 23:38:23
【问题描述】:
我有一个 Recyclerview 显示来自外部存储的图片网格。在我测试过的所有设备上,包括小米、Nexus7、三星 S3、one+2、Moto G-2 等,recyclerview 都能正确显示图片。我正在使用 Glide 图像加载库来加载图片。
我已经使用以下设置了适配器
savedPhotosGridLayoutManager = new GridLayoutManager(application, SPAN_COUNT);
savedPhotosGrid.setLayoutManager(savedPhotosGridLayoutManager);
savedPhotosGrid.addItemDecoration(new ItemOffsetDecoration(application, R.dimen.grid_save_spacing));
savedPhotosGrid.setAdapter(savedPhotosGridAdapter);
savedPhotosGrid.setHasFixedSize(true);
一行中的一个项目具有以下xml。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/item_recycler_view">
<ImageView
android:id="@+id/savedPhoto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:transitionName="imageScale" />
<ImageView
android:id="@+id/mask"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/savedPhoto"
android:layout_alignEnd="@+id/savedPhoto"
android:layout_alignLeft="@+id/savedPhoto"
android:layout_alignRight="@+id/savedPhoto"
android:layout_alignStart="@+id/savedPhoto"
android:layout_alignTop="@+id/savedPhoto"
android:background="@drawable/item_recycler_view"
android:clickable="true" />
</RelativeLayout>
我使用 Glide 将图像加载到其中。
Glide.with(context).load(savedImageFilePaths.get(i)).override(100, 100).centerCrop().into(viewHolder.savedImage);
出于某种奇怪的原因,在三星 S4 上,recyclerview 项目无法正确显示。行看起来被裁剪,应该是正方形(因为我正在加载 100 x 100 的图像),是它的裁剪版本。宽度正确,而行高不正确(比应有的短)。
只有当我将 xml 中的值硬编码为 100 dp x 100 dp 时,它才会在 S4 上正确显示。这显然很奇怪,因为我测试应用程序的所有其他设备都在网格(recyclerview)中正确显示方形图像。
这是一个错误还是我在某些地方出错/遗漏了什么?
【问题讨论】:
-
我相信这是一个错误。三星设备因此类问题而闻名。
-
你确定吗?我想确认一下,这样我就可以继续了。我不想硬编码宽度和高度值(100 dp)
-
我不确定这个特殊情况,但我看到三星设备有很多类似的问题。
标签: android android-recyclerview samsung-mobile