4

I have RecyclerView with GridLayoutManger

RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.movie_posters_recycler_view);
recyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));

Each RecyclerView's item represented by following layout

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/movie_item_poster_image_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true" />

</FrameLayout>

Currently I have such result

layout1

I want to do this

layout2

Yuriy Seredyuk
  • 1,643
  • 2
  • 15
  • 18

5 Answers5

4
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <ImageView
        android:id="@+id/movie_thumbnail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"
        android:adjustViewBounds="true"/>
</FrameLayout>

This should work

am5a03
  • 506
  • 7
  • 24
0

Replace your image view with this one

<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/movie_item_poster_image_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true" />
Atiq
  • 14,435
  • 6
  • 54
  • 69
  • It doesn't keep aspect ratio – Yuriy Seredyuk May 07 '16 at 20:34
  • images your getting are smaller buddy if you want a layout like that manually set height and width of your `ImageView` in dp – Atiq May 07 '16 at 22:20
  • Yes, but for example 200dp width is good for 7" tablet and bad for 9" one and so on. Thats the problem. I wanted to find out solution to stretch images automatically depending on free space on the screen. – Yuriy Seredyuk May 07 '16 at 22:50
  • so include different xml for different screens like , 1 for 7 inch and 1 for 10 inch and i for phones, you can put them in different folders in res folder but make sure to keep the name of the xml same and android will automatically use the one with respect to device. – Atiq May 08 '16 at 06:25
0

please add to scaltype to image view in your adapter to fitxy

0

Take a look at this answer: https://stackoverflow.com/a/26575808/4729523.

You just need to keep the image's aspect ratio (3/4 or 9/16).

Community
  • 1
  • 1
Rafa0809
  • 1,733
  • 21
  • 24
0

Using android:scaleType="fitXY" in ImageView attributes should stretch the image inside the ImageView.

AhmedAbdelaal
  • 286
  • 2
  • 6