xml - 使cardview中的两个项目出现在一行中
问题描述
我正在使用 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 的一行中,我希望出现多个
解决方案
使用 ReccyclerView 的网格布局管理器,将 2 作为第二个参数,用于显示 2 列。
RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(this, 2);
recyclerView.setLayoutManager(mLayoutManager);
推荐阅读
- acumatica - 利用具有自定义补货需求的创建采购订单处理屏幕
- r - 无法让 na.rm=TRUE 为函数工作
- angular - 在 Angular 中构建后 URI 无法访问
- h2o - 版本不匹配。H2O 是 3.22.0.1 版本,但是 h2o-python 包是 0.0.local 版本
- python-3.x - PyArrow 表到 PySpark 数据框的转换
- python - 使用 Python 的配置文件直方图(错误:“FutureWarning:...”
- r - 如何使用 R 中的测试数据获得特征重要性?
- python - AssertionError:图像大小不同,分割图像时出错
- python - 如何在 python 中处理异步测试?
- latex - LaTeX中的Macron重音(字母上的一个条)不起作用