使cardview中的两个项目出现在一行中
Making two items in cardview appear in one line
我正在使用 firebase 数据库在回收站视图中列出项目,我希望两个项目像这样在同一行上:
但对我来说它是这样显示的
这是我的卡片视图列表布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginTop="20dp"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
app:cardElevation="15dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/product_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Product Name"
android:textAlignment="center"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="@color/design_default_color_primary_dark"/>
<ImageView
android:id="@+id/product_image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="@+id/product_name"
android:scaleType="centerCrop"
android:layout_marginTop="2dp"/>
<TextView
android:id="@+id/product_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Product Price"
android:textAlignment="center"
android:textSize="18sp"
android:textStyle="bold"
android:layout_below="@id/product_image"
android:textColor="@color/design_default_color_primary_dark"/>
<TextView
android:id="@+id/product_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Product Description"
android:textAlignment="center"
android:textSize="16sp"
android:textStyle="bold"
android:layout_marginTop="2dp"
android:layout_below="@id/product_price"
android:textColor="@color/design_default_color_primary_dark"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
我想以某种方式做到这一点,而不是只有一个出现在 recyclerview 的一行中,我希望出现多个
为 RecyclerView 使用网格布局管理器,第二个参数为 2,用于显示 2 列。
RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(this, 2);
recyclerView.setLayoutManager(mLayoutManager);
我正在使用 firebase 数据库在回收站视图中列出项目,我希望两个项目像这样在同一行上:
但对我来说它是这样显示的
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginTop="20dp"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
app:cardElevation="15dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/product_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Product Name"
android:textAlignment="center"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="@color/design_default_color_primary_dark"/>
<ImageView
android:id="@+id/product_image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="@+id/product_name"
android:scaleType="centerCrop"
android:layout_marginTop="2dp"/>
<TextView
android:id="@+id/product_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Product Price"
android:textAlignment="center"
android:textSize="18sp"
android:textStyle="bold"
android:layout_below="@id/product_image"
android:textColor="@color/design_default_color_primary_dark"/>
<TextView
android:id="@+id/product_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Product Description"
android:textAlignment="center"
android:textSize="16sp"
android:textStyle="bold"
android:layout_marginTop="2dp"
android:layout_below="@id/product_price"
android:textColor="@color/design_default_color_primary_dark"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
我想以某种方式做到这一点,而不是只有一个出现在 recyclerview 的一行中,我希望出现多个
为 RecyclerView 使用网格布局管理器,第二个参数为 2,用于显示 2 列。
RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(this, 2);
recyclerView.setLayoutManager(mLayoutManager);