This has been stumping me for a while, and I’m not sure how to fix it.
Supposing I have the following layout: 2 ImageViews with a TextView under each ImageView. The images are being retrieved remotely. I would like each ImageView to take about 40% of the width of the Activity they’re in, with white space under them. The TextViews will be about 5% smaller, centered below each ImageView.
What I tried:
Put each pair of ImageView and TextView in their own LinearLayout, so 2 LinearLayouts, with each LinearLayout’s layout_width set to fill_parent and equal layout_weight (0.5) for both.
Each ImageView had a layout_width of fill_parent and a layout_margin of 15dip. layout_height was set to wrap_content (this was the parameter I wasn’t sure how to set).
That worked fine but the problem was that all the incoming images were of different sizes and ratios, so they looked weird side by side.
I proceeded to set:
android:scaleType=”centerCrop”
android:adjustViewBounds=”true”
That helped but each ImageView was still different size sometimes. At this point, I just put each ImageView at a fixed width 100 dip or so
to both ImageViews, and that helped, but of course with bigger size devices this will look weird. How can I achieve what I’m trying to accomplish?
On the second option, try it without “AdjustViewBounds” remember:
But here is what i would do in your case:
And it will look like on larger screens:
And on smaller screens:
I prefer center in this case, because if you have smaller pictures then they will look better. I try to avoid fixed sizes if you can, because as you said it won’t look good on larger devices.
You can also make different layouts for each sceen size. But you will have to mantain all of them. Check Supporting Multiple Screen Sizes (if you haven’t already ;)).