我正在使用 RecyclerView 在网格布局中显示项目。下面是模拟器的图像和我需要实现的期望结果。左侧(执行)图像是我的模拟器上的输出,而右侧(所需)是我想要实现的输出。
活动布局 XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parentLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#d3c3c3">
<include
android:id="@+id/toolBarIncluded"
layout="@layout/toolbar_new_layout" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolBarIncluded"
android:orientation="vertical"
android:weightSum="1">
<RelativeLayout
android:id="@+id/recyclerAdView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="0.65"
android:background="#009688" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/recyclerAdView"
android:layout_gravity="center"
android:layout_weight="0.35"
android:background="#00000000"
android:gravity="center">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerGridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:background="#00000000"
android:foregroundGravity="center" />
</RelativeLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
列表项 XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llGridItemLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="6dp"
android:background="@drawable/drawable_grid_item_background"
android:gravity="center"
android:paddingStart="2dp"
android:paddingEnd="2dp"
android:orientation="vertical">
<ImageView
android:id="@+id/ivItemIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:src="@drawable/ic_new_receipt_wrong" />
<TextView
android:layout_marginTop="6dp"
android:id="@+id/tvItemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1" …Run Code Online (Sandbox Code Playgroud) android grid-layout gridlayoutmanager android-recyclerview recyclerview-layout