如何使图片库应用程序在所有不同的屏幕尺寸上看起来都一样?

How to make Image Gallery app look same on ALL different screen sizes?

我正在开发像 Image Gallery 这样的应用程序,其中包含从 Web 获取的图像。所有图像具有相同的宽度 200px 和高度 280-300px。我将 RecyclerViewAdapter.ViewHolder 一起使用,将 GridLayoutManager 与跨度数 = 2 一起使用。使用 Picasso 库加载图像。

item_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<ImageView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tile_picture"
    android:layout_width="match_parent"
    android:layout_height="260dp"
    android:layout_margin="1dp"
    android:scaleType="centerCrop"/>

在我的设备上 5" 720x1280 它看起来不错。 Screenshot 但是当我在其他设备上启动应用程序时,它看起来不太好...... 在 5.5" 1080x1920 上,图像之间有额外的边距。 在旧 3.7" 480x800 上,只有一个跨度,宽度比半屏尺寸大一点。 我建议,因为 android:layout_height="260dp" 是硬编码的。 那么,如何才能在不同的设备上获得相同的外观?

我建议你实现一个自定义视图,在onMeasure中获取屏幕宽度,然后传递宽度的一半:

setMeasuredDimension(width/2, height);

这将保证您在任何设备上的一半屏幕上都有图像。