Android Horizontal RecyclerView wrap_content

I am making a horizontal RecyclerView with photos in it, and I ran into the wrap_parent problem. If I embed my View width = wrap_content , this is the width of the screen width, although the image consumes very little space. If I change the wrap_content value to some value, it works fine. The recycle image has a height of 75dp 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> 

Screenshot

Blue is the screen, and light blue is the photograph. The problem is that I have case 1 when I set the view to wrap_content .

DECISION:

I recently solved this problem, is there some kind of error or something similar when you are trying to use the scalable ImageView wrap_parent. This does not work very well. To solve this problem, I resized each photo to its final size before placing it in RecyclerView. In the end, I again have a small space between ImageView, and I decided by adding padding=0 and margin=0 to the childern RecyclerView.

+5
source share
1 answer
  • First solution: LinearLayout weight attribute

As long as you use LinearLayout for this view, you can use this attribute for all your ImageView views:

  android:layout_weight="{number_value}" 

In short, if you add the same value for weight for all your ImageView tags, they will calculate the same space, but no more than their parent view attributes.

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

Read this issue:

What does android mean: layout_weight?

If you are still experiencing a problem, call me.

  1. Second solution: ImageView scale attribute

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

Consider also using TableLayout or GridLayout for this purpose.

0
source

Source: https://habr.com/ru/post/1238076/


All Articles