如何在Android App中解决此类别的布局问题

时间:2019-10-09 07:38:45

标签: android xml android-studio android-layout android-adapter

我的应用程序中的类别布局有问题。问题是下一类别从下一行开始。我想显示它的混合布局。不像另一个类别将显示在该类别下面。请帮助我解决此问题。我已经在互联网上搜索过,但不知道如何解决。

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>

3 个答案:

答案 0 :(得分:1)

<?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>

答案 1 :(得分:1)

我可以在recyclerview中使用项目管理器gridview 2列在您的项目xml中执行此操作

enter image description here

答案 2 :(得分:1)