0

Есть fragment на котором есть два элемента отображены в xml. Первый (кастомный) привязан "наверху":

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

Второй (RecyclerView) привязан "внизу":

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

Но проблема в том, что если я задаю (как мне нужно) параметр высоты как wrap_content он занимает все свободное пространство и отображается "сверху" (поверх первого элемента), если же задам высоту как константу - то отображается, как положено снизу.

xml фрагмента

<?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>

Вопрос: что нужно добавить или изменить что бы при параметре android:layout_height="wrap_content" горизонтальный RecyclerView отображался внизу?

xml элемента RecyclerView

<?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>
7
  • 1
    Какая у вас версия сапорт либ? Если я правильно помню RecyclerView научился правильно работать с android:layout_height="wrap_content" только начиная с версии 23.4.0. Хотя это касалось вертикального режима, в горизонтальном не уверен что android:layout_height="wrap_content" работает правильно.
    – xkor
    16 сен 2016 в 8:21
  • 1
    можете попробовать "верх" RecyclerView привязать к "низу" CurrentWeatherView 16 сен 2016 в 8:24
  • @metalurgus Можно- я вами согласен. Но меня интересует все таки возможность отображения, в котором нижний список был привязан к "дну" экрана и в
    – abbath0767
    16 сен 2016 в 8:49
  • @xkor Версия 23.2.1. Но у меня studio отображает ее как последнюю.
    – abbath0767
    16 сен 2016 в 8:51
  • значит давно SDK не обновляли, последняя 24.2.1
    – xkor
    16 сен 2016 в 8:54

1 ответ 1

2

Если я правильно помню RecyclerView научился правильно работать с android:layout_height="wrap_content" только начиная с версии 23.4.0. Хотя это касалось вертикального режима, в горизонтальном не уверен что android:layout_height="wrap_content" работает правильно.

В общем попробуйте использовать последнюю версию сапорт либ. На данный момент это 24.2.1.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.