如何解决 Android 应用程序中的此类布局问题

how to fix this category Layout Problems in Android App

我的应用程序中的类别布局有问题。问题是下一个类别从下一行开始。我想给它展示一个混合布局。不像另一个类别会显示在该类别下方。请帮我解决这个问题。我在网上搜索过,但不知道如何解决。

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>

像这样

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:padding="5dp"

            android:text="Demo Text" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:padding="5dp"
            android:text="Demo Text" />


        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:padding="5dp"
            android:text="Demo Text 2" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:padding="5dp"

            android:text="Demo Text" />


    </LinearLayout>

</LinearLayout>

也许你可以在你的项目中这样做 xml n 在你的 recyclerview 中使用布局管理器网格视图 2 列

您必须使用 canvas 生成自定义布局。 请浏览链接

https://developer.android.com/training/custom-views/custom-drawing

https://medium.com/over-engineering/getting-started-with-drawing-on-the-android-canvas-621cf512f4c7

https://medium.com/mindorks/how-to-create-custom-views-141dc0570e57