首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Android GridLayoutManager整行背景图片

Android GridLayoutManager整行背景图片
EN

Stack Overflow用户
提问于 2018-11-30 07:15:42
回答 1查看 250关注 0票数 0

我正在尝试做简单的布局,但不能让它工作。目标是让活动显示(可配置)像书架上的书的数量。

我在主活动中有回收器视图(这样我就可以滚动所有的内容)和网格布局管理器(这样我就可以配置行中的图书数量)。

代码语言:javascript
运行
复制
<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图片,而不是一整排包装的图片。

代码语言:javascript
运行
复制
<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 -我有每个图像下的“新”背景(棕色),但我需要这一个背景覆盖整行

EN

回答 1

Stack Overflow用户

发布于 2018-11-30 20:58:54

这是一个变通办法,你必须将你的背景(棕色)货架图像分成3个相等的部分。

数据的第一项将具有图像的第一部分,而行的最后一项将具有图像的最后部分。第二个项目有中间部分。

这样,您可以将书架背景设置为整行,而不只是一本/书。

我希望你明白我想说的话。首先,使用某个编辑器或其他工具剪切背景图像或进行绘制。

假设你有5个项目在一行。

item 1 -图像的part1。item 2 -图像的part2。item 3 -图像的part2。item 4 -图像的part2。item 5 -图像的part3。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53548987

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档