【问题标题】:Show a horizontally large background in back of Recyclerview在 Recyclerview 后面显示水平大背景
【发布时间】:2019-01-27 14:10:58
【问题描述】:

我有一个长宽的背景图像,我想放在一个包含 8 个项目的 Recyclerview 后面(Recyclerview)。这只有使用我在下面编码的水平滚动视图才有可能,但是有没有办法不使用水平滚动视图并获得相同的结果?

<HorizontalScrollView
        android:id="@+id/HSV"
        android:layout_width="wrap_content"
        android:layout_height="match_parent">
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@drawable/back"
            android:paddingLeft="2.5dp"
            android:paddingRight="2.5dp"
            android:orientation="vertical">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </RelativeLayout>
    </HorizontalScrollView>

使用上面的代码,我得到了所需的输出,但是当我删除 Horizo​​ntalScrollView 时,图像在宽度上压缩并松散了它的形状,我希望在滚动 recyclerview 时图像滚动 那就是我想要的图片: ![in Background is the aforementioned image and this eight Item are in recycler view and I want as the items finishing the background image is finishing too. ]1

【问题讨论】:

  • 给出你想要的链接或演示。那会很有帮助。
  • @Alok 附demo
  • 我已经回答了您的问题,请查看并告诉我您的情况如何。 :)

标签: android android-studio android-recyclerview horizontalscrollview


【解决方案1】:

在布局中这样设计。并将图像中卡片的布局传递给Android中的适配器。将背景设置为约束布局或Recyclerview。 当您拥有 Recyclerview 时,无需添加 Horizo​​ntal Scrollview。只需将布局管理器作为水平传递

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical"
        android:background="@color/secondaryColor"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <androidx.recyclerview.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>idget.ConstraintLayout>

【讨论】:

  • 不,这不能解决我的问题,正如我所说,没有水平滚动视图,我的长背景被压缩,只有回收器滚动
  • 你做到了吗。我认为您正在支持该设计的选项卡,并且您确实需要非常大的图像并转换为 WebP。考虑一个支持 10.1 平板电脑的高分辨率图像并将其转换为 WebP 并使用它
【解决方案2】:

我想知道您的查询是否正确,所以您希望您的RecyclerView 水平滚动。我建议同样使用LinearLayoutManager,这样您就可以在LinearLayoutManager 的参数中将Scrolling 常量传递给Horizo​​ntal。

要阅读它,请继续阅读LinearLayoutManager

当你得到它时,就在你身上这样做Java Class。

RecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, true));

我也有这个 youtube 链接给你,如果你没有得到你想要的。在这里,您将获得如何做到这一点的完整演示,并实现它。 Horizontal RecyclerView

我希望这将回答您的问题。谢谢:)

【讨论】:

  • 不,这绝对不是我的问题。我想要一种具有水平大背景图像的水平 Recyclerview 的方法。随着 Recyclerview 项目的完成,图像也完成了。我提到的情况的背景是我关心的
猜你喜欢
  • 2021-11-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-20
  • 2020-05-03
  • 2013-10-28
  • 2020-12-17
  • 1970-01-01
相关资源
最近更新 更多