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

231 Views Asked by At

I'm developing the app like Image Gallery with images fetching from web. All images have same width 200px and height 280-300px. I use RecyclerView with Adapter.ViewHolder and GridLayoutManager with count of spans = 2. Images loading with Picasso library.

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"/>

On my device 5" 720x1280 it's look fine. Screenshot But when I launch app on other devices, it's look not so good... On 5.5" 1080x1920 there are extra margins between images. On old 3.7" 480x800 there is only one span, width bit more, than half-screen size. I suggest, because android:layout_height="260dp" hardcoded. So, how can I get same look on different devices?

1

There are 1 best solutions below

1
On BEST ANSWER

I can suggest you implement a custom view, and in onMeasure get the screen width, and then pass half of the width:

setMeasuredDimension(width/2, height);

This will guarantee that on any device you'll have an image on half the screen.