0

Image of list I wish to replicate.

I am designing an app that displays a list similar to the one displayed in the image. I actually will be implementing 3 lists of the same kind stacked below each other vertically(Each row representing output from 3 different API calls, So basically I have 3 different horizontal-recycler views). My problem is how do I maintain uniform width and height across cards in one row as well as across the 3 rows. The API response from the 3 sources that is mapped into the 3 rows, returns images of different sizes for each row. Is hard coding the size the only solution?If so, how will I maintain the size across different screen sizes?

Coolio Cena
  • 69
  • 1
  • 4
  • What do you define as "uniform" size? Using `dp` size is safest bet - UI might require more scrolling on devices with small screens, but it should stay readable. Using percent-of-screen size dimensions are not recommended for anything with text because it might become illegible on smaller screens while becoming over-sized (and stretches out small images) on tablets etc. – Pawel Jul 08 '18 at 19:22

1 Answers1

0

Is hard coding the size the only solution?

It is best fit solution for your requirement. For that you can make a dimen.

<dimen name="card_size">100dp</dimen>

And give your card size in every item layout like.

<CardView
   android:layout_width="@dimen/card_size"
   android:layout_height="@dimen/card_size"
   />

how will I maintain the size across different screen sizes?

Now second thing is to make responsive card size for different screens.

For that you have two options.

  1. (Long historical method) Put dimen- card_size in every screen value folder. See this link.
  2. (Short method) I prefer this method.

In this you will use sdp library and just use 100sdp instead of 100dp.

See sdp library work.

enter image description here

Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212