我正在尝试制作简单的布局,但无法正常工作。目标是要有活动来显示(可配置)书架上的书本数量。
我使用网格布局管理器在主要活动中拥有回收站视图(以便可以滚动所有视图)(因此我可以在行中配置书数)。
<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个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-每张图片下方都有“新”背景(棕色),但整行都需要这个背景覆盖
答案 0 :(得分:0)
这是一种解决方法,您必须将背景(棕色)架子图像切成3个相等的部分。
数据的第一项将具有图像的第一部分,而行的最后一项将具有图像的最后部分。而第二项位于中间。
通过这种方式,您可以将书架背景设置为整行,而不仅仅是一本书。
我希望你能明白我的意思。首先,使用一些编辑器或某些东西或绘画来剪切背景图像。
假设您连续有5个项目。
项目1 -图片的第1部分。 项目2 -图片的第2部分。 项目3 -图片的第2部分。 项目4 -图片的第2部分。 项目5 -图片的第3部分。