Совместите reclyerview Чайлдерс снизу - PullRequest
0 голосов
/ 08 ноября 2019

enter image description here

Я пытаюсь сделать график с reclyerview. Проблема, с которой я столкнулся, заключается в том, что я не могу выровнять дочерние элементы снизу вместо вершины reclyerview.

Я пробовал, reverseLayout и stackFromEnd

Я искал влево и вправо. До сих пор понятия не имею, почему это происходит.

Может кто-нибудь, пожалуйста, помогите мне. Любые полезные идеи будут оценены.

Ответы [ 2 ]

1 голос
/ 08 ноября 2019

Менеджеры по расположению выравнивают элементы по верху по умолчанию, потому что это наиболее стабильно в случае, если RecyclerView имеет высоту wrap_content, что может вызвать некоторые проблемы с макетом.

Если ваш RecyclerView имеет фиксированный размерВы можете попытаться расширить используемый менеджер макетов, чтобы заставить его размещать элементы снизу:

// inside your activity or fragment where you're initializing RecyclerView
recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) {
      @Override
      public void layoutDecoratedWithMargins(@NonNull View child, int left, int top, int right, int bottom) {
          // calculate available space in recyclerView
          int offset = getHeight() - getPaddingTop() - getPaddingBottom();
          // subtract height of item being laid out
          offset -= bottom - top;
          // lay out item lower than usual
          super.layoutDecoratedWithMargins(child, left, top + offset, right, bottom + offset);
      }
});
0 голосов
/ 08 ноября 2019

Я вроде понял это.

Поскольку у меня есть статическая высота, я создал еще одну обертку вокруг дочернего элемента, которая была выровнена по низу, и parrent был задан как конкретная высота.

<androidx.constraintlayout.widget.ConstraintLayout 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="80dp"
        android:layout_height="200dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginRight="8dp"
        >

<androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent">


        <TextView
                android:id="@+id/tv_time"
                style="@style/BoldWhiteText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="7.5"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toTopOf="parent" />
 </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
...