【发布时间】:2019-03-03 15:15:47
【问题描述】:
我正在尝试制作简单的布局,但无法正常工作。目标是让活动显示(可配置的)书架上的书籍数量。
我在主要活动中有回收站视图(所以我可以滚动所有这些)和网格布局管理器(所以我可以配置行中的书籍数量)。
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/bookshelfRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
</android.support.v7.widget.RecyclerView>
我的问题是,我必须为每一行设置背景图像,但图像用于每本书。就像当我想要一排 3 本书时,我有 3 张 bcgr 图像,而不是一张包裹整行。
<RelativeLayout
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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shelfcell_background">
<ImageView android:id="@+id/imgThumbnail"
android:layout_width="103dp"
android:layout_height="134dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_centerInParent="true"
android:gravity="center_vertical"
android:layout_marginLeft="20dp"
tools:ignore="RtlCompat"
android:layout_marginTop="1dp"/>
</RelativeLayout>
如何设置整行的背景图片(现在不管有多少本书)?
bookshelf - 我在每张图片下都有“新”背景(棕色),但我需要这个背景覆盖整行
【问题讨论】:
-
你能发一些截图吗?
-
屏幕即书架
标签: android android-recyclerview grid-layout