5

I'm making horizontal RecyclerView with photos in it, and I have faced up with wrap_parent problem. If I put in my View width = wrap_content, it is screenWidth width, although image consumes very small space. If I change wrap_content to some value it works perfectly.RecyclerView is 75dp height and match_parent.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="75dp"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:foreground="@drawable/card_foreground">
    <ImageView
        android:id="@+id/bitmap"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/image" />
</LinearLayout>

Screenshoot

Dark blue is screen and light blue is photos. Problem is I have case 1 when I set view to wrap_content.

SOLUTION:

I have solved this problem recently, there is some bug or something simmilar, when you try to have on scaled ImageView wrap_parent. It doesn't work very well. To solve this, I have resized every photo to final size before put it in RecyclerView. In adition, I have some small space between ImageView again, and I have solved by adding padding=0 and margin=0 to childern of RecyclerView.

Filip V
  • 435
  • 4
  • 16

1 Answers1

0
  1. First solution: LinearLayout weight attribute

As long as you would use for that view LinearLayout you may use for all of your ImageView views this attribute:

    android:layout_weight="{number_value}"

Shortly, if you add for all of your ImageView views the same value for weight they would get calculated the same space, but not more than their parent view attributes.

http://developer.android.com/guide/topics/ui/layout/linear.html

Read please this issue:

What does android:layout_weight mean?

If you still face the problem, give me a call.

  1. Second solution: ImageView scale attribute

    For ImageView you can use scaleX, scaleY, scaleType attributes. For having the same height you should use the same scaleY value for all your ImageView items.

Think also about using TableLayout or GridLayout for this purpose.

Community
  • 1
  • 1
piotrek1543
  • 19,130
  • 7
  • 81
  • 94
  • You can add layout_weight on RecylerView children – Filip V Dec 14 '15 at 09:08
  • 1
    Oh sorry, I wanted to write "You can't", however I've solved this problem check my solution if you are interested in. Thanks. – Filip V Dec 14 '15 at 09:17
  • so you had a padding and margin and you didn't write about them? :-) – piotrek1543 Dec 14 '15 at 09:20
  • No, I have unscaled images, and there is problem with wrap_parent in RecylerView when imageView need to scale it. And additional problem was padding which I haven't set anywhere but when i set on zero it works – Filip V Dec 14 '15 at 09:22