Recyclerview с использованием gridlayout, показывающего дополнительный интервал - PullRequest
0 голосов
/ 16 октября 2019

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

Ниже приведен код расположения фрагмента

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorShopListingBackground"
    android:orientation="vertical">

    <androidx.viewpager.widget.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="@dimen/margin_124"
        android:background="@android:color/white" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/margin_8"
        android:layout_marginTop="@dimen/margin_8"
        android:layout_marginRight="@dimen/margin_8"
        android:layout_marginBottom="@dimen/margin_16"
        android:background="@drawable/bg_dashboard_categories"
        android:elevation="@dimen/margin_16"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tv_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/margin_16"
            android:layout_marginRight="@dimen/margin_16"
            android:layout_marginTop="@dimen/margin_16"
            android:fontFamily="@font/montserrat_bold"
            android:textSize="@dimen/text_size_18"
            android:textColor="@color/colorHandPickedOffer"
            android:text="@string/txt_handpicked_offers" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rv_categories"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/margin_16"
            android:background="@drawable/bg_dashboard_categories"
            android:layout_below="@id/tv_title"
            android:layoutAnimation="@anim/grid_layout_animation_from_bottom"/>

    </RelativeLayout>
</LinearLayout>

Ниже приведен элемент списка

<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:background="@color/colorCategoryDivider"
    android:paddingRight="@dimen/margin_1"
    android:paddingEnd="@dimen/margin_1"
    android:paddingBottom="@dimen/margin_1"
    android:paddingTop="@dimen/margin_1"
    android:gravity="center"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/rl_category"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:gravity="center_horizontal"
        android:orientation="vertical"
        android:paddingBottom="@dimen/margin_16"
        android:minWidth="@dimen/margin_136">

        <ImageView
            android:id="@+id/iv_category_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="@dimen/margin_16"
            android:src="@drawable/fashion" />

        <TextView
            android:id="@+id/tv_category_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_below="@id/iv_category_image"
            android:fontFamily="@font/montserrat_semi_bold"
            android:hint="@string/txt_category_name"
            android:layout_marginTop="@dimen/margin_16"
            android:gravity="center"
            android:textSize="@dimen/text_size_12"
            android:textColor="@color/colorCategoryText"
            android:textStyle="bold" />

    </LinearLayout>

</LinearLayout>

ниже изображение с ошибкой

Image with error

Ответы [ 2 ]

0 голосов
/ 17 октября 2019

Я проверял, и я верю, что Библиотека Вызывается flexbox, поможет вам, его потребуется немного преобразовать, но он довольно прост в использовании и идеально подходит для такой панели, как вы хотите

Вот выдержка из страницы, которая, я думаю, вам очень поможет

Второй - это FlexboxLayoutManager, который можно использовать в RecyclerView.

RecyclerView recyclerView = (RecyclerView) context.findViewById(R.id.recyclerview);
FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(context);
layoutManager.setFlexDirection(FlexDirection.COLUMN);
layoutManager.setJustifyContent(JustifyContent.FLEX_END);
recyclerView.setLayoutManager(layoutManager);
or for the attributes for the children of the FlexboxLayoutManager you can do like:

mImageView.setImageDrawable(drawable);
ViewGroup.LayoutParams lp = mImageView.getLayoutParams();
if (lp instanceof FlexboxLayoutManager.LayoutParams) {
    FlexboxLayoutManager.LayoutParams flexboxLp = (FlexboxLayoutManager.LayoutParams) lp;
    flexboxLp.setFlexGrow(1.0f);
    flexboxLp.setAlignSelf(AlignSelf.FLEX_END);
}

ПреимуществоИспользование FlexboxLayoutManager заключается в том, что он перерабатывает представления, которые выходят за пределы экрана, для повторного использования для представлений, отображаемых при прокрутке пользователя, вместо того, чтобы надувать каждое отдельное представление, что потребляет намного меньше памяти, особенно когда количество элементов, содержащихся в контейнере Flexbox, велико.

0 голосов
/ 16 октября 2019

установить android: layout_height = "wrap_content" для android: layout_height = "match_parent"

...