There is a fragment on which there are two elements displayed in xml . The first (custom) is tied up at the top:

 android:layout_alignParentTop="true" android:layout_alignParentStart="true" 

The second (RecyclerView) is tied "below":

 android:layout_alignParentBottom="true" android:layout_alignParentStart="true" 

But the problem is that if I set (as I need) the height parameter as wrap_content it takes up all the free space and is displayed "above" (above the first element), if we set the height as a constant, it is displayed as it should be below.

xml fragment

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colorPrimary" > <com.luxary_team.openweather.ui.view.CurrentWeatherView android:id="@+id/current_weather_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="16dp" android:layout_marginTop="16dp" android:layout_alignParentTop="true" android:layout_alignParentStart="true"> </com.luxary_team.openweather.ui.view.CurrentWeatherView> <android.support.v7.widget.RecyclerView android:id="@+id/recycler_view_general_fragment" android:layout_width="match_parent" android:layout_height="150dp" android:orientation="horizontal" android:layout_alignParentBottom="true" android:layout_alignParentStart="true"> </android.support.v7.widget.RecyclerView> </RelativeLayout> 

Question: what needs to be added or changed in order for the android:layout_height="wrap_content" horizontal RecyclerView displayed below?

xml of the RecyclerView element

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="48dp" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:layout_marginRight="8dp" android:gravity="center_horizontal" android:orientation="vertical"> <TextView android:id="@+id/day_text_view_list_item_bottom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" android:text="ПТ"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/bottomUnactiveListItem" android:gravity="center_horizontal" android:orientation="vertical"> <android.support.v7.widget.AppCompatImageView android:id="@+id/icon_image_view_list_item_bottom" android:layout_width="42dp" android:layout_height="42dp" android:background="@null" app:srcCompat="@drawable/testicon" tools:ignore="MissingPrefix"/> <TextView android:id="@+id/temperature_text_view_list_item_bottom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="16 C" android:textSize="16sp" android:textStyle="bold"/> </LinearLayout> </LinearLayout> 
  • one
    What is your version of sapport lib? If I remember correctly RecyclerView learned to work correctly with android:layout_height="wrap_content" only starting from version 23.4.0. Although this concerned the vertical mode, in the horizontal mode I’m not sure that android:layout_height="wrap_content" works correctly. - xkor
  • one
    You can try RecyclerView's “top” tied to “bottom” CurrentWeatherView - Vladyslav Matviienko
  • @metalurgus Can- I agree with you. But I am still interested in the possibility of displaying in which the bottom list was tied to the "bottom" of the screen and in - abbath0767
  • @xkor Version 23.2.1. But my studio displays it as the last. - abbath0767
  • so the SDK has not been updated for a long time, the last 24.2.1 - xkor

1 answer 1

If I remember correctly RecyclerView learned to work correctly with android:layout_height="wrap_content" only starting from version 23.4.0. Although this concerned the vertical mode, in the horizontal mode I’m not sure that android:layout_height="wrap_content" works correctly.

In general, try using the latest version of Saport Lieb. At the moment it is 24.2.1.