GridLayoutManager дает одинаковую высоту для элемента в тех же строках - PullRequest
0 голосов
/ 07 июля 2019

У меня есть вид рециркулятора с GridLayoutMananger, и по какой-то причине все элементы в одинаковых строках имеют одинаковую высоту. Это выглядит так: enter image description here

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

Я бы хотел, чтобы каждый предмет имел необходимую ему высоту и не более.

Вот код в java:

GridLayoutManager layoutManager = new GridLayoutManager(this,3 );
    recycle_confirm_command = (RecyclerView) findViewById(R.id.recycle_all_command);
    recycle_confirm_command.setLayoutManager(layoutManager);
    adapter = new ListCommandAdapter(this, List_to_confirm, btn_total);
    recycle_confirm_command.setAdapter(adapter);

А вот XML-адаптер для элемента:

 <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:layout_marginEnd="10dp"
    android:layout_marginStart="10dp"
    android:layout_marginTop="10dp"
    card_view:cardBackgroundColor="@color/UnderPrim"
    card_view:cardCornerRadius="10dp"
    android:background="@drawable/my_button_xml">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <TextView
            android:id="@+id/lbl_command"
            android:layout_width="wrap_content"
            android:layout_alignParentLeft="true"
            android:text="eeee\nrfkfkkf\nfkfkfkf\ndkdkdkd\j\nkdkdkd"
            android:layout_toLeftOf="@id/lbl_time_of_command"
            android:layout_height="wrap_content" />


        <TextView
            android:id="@+id/lbl_time_of_command"
            android:layout_width="wrap_content"
            android:text="time"
            android:layout_alignLeft="@id/lbl_numer_of_command"
            android:layout_alignParentRight="true"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/lbl_numer_of_command"
            android:layout_width="wrap_content"
            android:layout_alignParentRight="true"
            android:gravity="bottom"
            android:layout_alignBottom="@id/lbl_command"
            android:text="numéro"
            android:layout_below="@id/lbl_time_of_command"
            android:layout_height="wrap_content" />



    </RelativeLayout>


</android.support.v7.widget.CardView>

CardView имеет «обернуть содержимое» в качестве высоты, потому чтоВес определяется высотой левого текстового обзора.Спасибо за помощь

1 Ответ

0 голосов
/ 07 июля 2019

Вам необходимо использовать StaggeredGridLayoutManager , чтобы иметь различную высоту для каждого элемента, т. Е. Иметь высоту в качестве содержимого переноса.Замените ваш GridLayoutManager следующим StaggeredGridLayoutManager

StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);

enter image description here

...