androidxmlandroid-studioandroid-layoutandroid-adapter

how to fix this category Layout Problems in Android App


I have a problem with the Category Layout in my App. The problem is that the next category starts in the next line. I want to show it a mixed layout. Not like another category will show below that category. Please help me to fix this issue. I have searched on the internet but don't know how to fix it.

Screenshot of Categories

item_category_list_adapter.xml

<?xml version="1.0" encoding="utf-8"?>
<layout 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">

    <data>

        <variable
            name="allWallpaperByCategory"
            type="com.panaceasoft.pswallpaper.viewobject.Category" />
    </data>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/constraintLayout3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp">

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

            <ImageView
                android:id="@+id/itemImageView"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:contentDescription="No Image"
                android:scaleType="centerCrop"
                app:imageUrl="@{allWallpaperByCategory.default_photo.img_path}"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                tools:ignore="HardcodedText"
                tools:srcCompat="@drawable/app_icon" />

            <View
                android:id="@+id/view52"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:background="@drawable/black_alpha_50"
                app:layout_constraintBottom_toBottomOf="@+id/itemImageView"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="@+id/itemImageView"
                app:layout_constraintVertical_bias="0.0" />

            <TextView
                android:id="@+id/productCountTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="8dp"
                android:text="@string/category__30wallpaper"
                android:textAlignment="viewStart"
                android:textColor="@color/md_grey_400"
                android:textSize="@dimen/font_body_size"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.498"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/categoryNameTextView"
                tools:ignore="MissingConstraints" />

            <TextView
                android:id="@+id/categoryNameTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="8dp"
                android:layout_marginBottom="8dp"
                android:textAlignment="viewStart"
                android:textColor="@color/md_grey_300"
                android:textSize="@dimen/font_h5_size"
                android:textStyle="bold"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="@+id/view52"
                tools:ignore="MissingConstraints"
                tools:text="20 Category" />

        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

Solution

  • Maybe you can do this in your item xml n in you recyclerview use layout manager gridview 2 columns

    enter image description here