android - 修复了使用 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>
我希望图像在滚动时会保持在背景中,但图像会变得与回收站视图高度一样大
解决方案
我在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
根据您的需要更改属性。上面的布局是从我的应用程序中截取的。我希望这会对你有所帮助。
推荐阅读
- postgresql - Postgres jsonb_set - 在大于当前数组的索引处添加数组元素
- vue.js - Vue Native Script 不想安装
- java - Unity3D - 使用 Gradle 构建 Android AppBundle 失败
- scheme - CPS 中的函数是否需要进行尾调用?
- java - 约束验证器基于父类中的另一个字段验证子类中的字段
- powershell-3.0 - 发送邮件后,我没有得到正确的输出
- javascript - 在javascript中循环移动数组
- angular - 带有 ObservableInput 的 AngularFireAuth 错误
- programming-languages - 关于 EOPL3 练习 6.31 的提示
- php - 将内容限制为购买了 Woocommerce 产品的人