我正在尝试做简单的布局,但不能让它工作。目标是让活动显示(可配置)像书架上的书的数量。
我在主活动中有回收器视图(这样我就可以滚动所有的内容)和网格布局管理器(这样我就可以配置行中的图书数量)。
<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 -我有每个图像下的“新”背景(棕色),但我需要这一个背景覆盖整行
发布于 2018-11-30 20:58:54
这是一个变通办法,你必须将你的背景(棕色)货架图像分成3个相等的部分。
数据的第一项将具有图像的第一部分,而行的最后一项将具有图像的最后部分。第二个项目有中间部分。
这样,您可以将书架背景设置为整行,而不只是一本/书。
我希望你明白我想说的话。首先,使用某个编辑器或其他工具剪切背景图像或进行绘制。
假设你有5个项目在一行。
item 1 -图像的part1。item 2 -图像的part2。item 3 -图像的part2。item 4 -图像的part2。item 5 -图像的part3。
https://stackoverflow.com/questions/53548987
复制相似问题