首页 > 解决方案 > 修复了使用 Recyclerview 滚动时的背景图像

问题描述

我有一个 Recyclerview,我必须放置一个在滚动时保持稳定的背景图像。

我尝试为父布局提供背景,还尝试使用背景图像添加框架布局。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
    android:background="@drawable/bg_alpha_main"
    android:orientation="vertical">


    <android.support.v7.widget.RecyclerView
        android:id="@+id/submenuRv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:nestedScrollingEnabled="true"
        app:layoutManager="android.support.v7.widget.GridLayoutManager"
        app:spanCount="2"
        tools:listitem="@layout/submenu_items" />

</LinearLayout>

我希望图像在滚动时会保持在背景中,但图像会变得与回收站视图高度一样大

标签: androidandroid-layoutbackground-image

解决方案


我在ConstraintLayout这里做的是我的布局文件

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:background="@drawable/full_background"
    tools:showIn="@layout/activity_main">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        tools:listitem="@layout/list_item" />

</android.support.constraint.ConstraintLayout>

RecyclerView根据您的需要更改属性。上面的布局是从我的应用程序中截取的。我希望这会对你有所帮助。


推荐阅读