android - 如何仅在 Scrollview/Recyclerview 的底部添加淡入淡出边缘?

标签 android android-recyclerview scrollview fading

enter image description here我使用 requiresFadingEdge=true 在底部添加淡入淡出效果,但问题是它也在顶部显示淡入淡出效果?如何在向下滚动时禁用顶部的淡入淡出效果?

我在底部附上了屏幕截图。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@color/grey">
  <android.support.v7.widget.RecyclerView
        android:id="@+id/list_recyclerview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="?attr/actionBarSize"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:spanCount="2"
        tools:itemCount="14"
        tools:layoutManager="android.support.v7.widget.GridLayoutManager"
        tools:listitem="@layout/layout_thermal_grid" />

 <View
        android:layout_width="match_parent"
        android:layout_height="@dimen/pad_150dp"
        android:layout_alignParentBottom="true"
        android:requiresFadingEdge="vertical"
        android:layout_marginBottom="@dimen/pad_50dp"
        android:fadeScrollbars="true"
        android:fadingEdgeLength="@dimen/pad_120dp"></View>


</RelativeLayout>

最佳答案

你可以使用这样的东西:

class BottomFadingEdgeScrollView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : RecyclerView(context, attrs, defStyleAttr) {

    override fun getTopFadingEdgeStrength() = 0f
}

然后在布局文件中:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@color/grey">

  <your.package.with.custom.widgets.BottomFadingEdgeScrollView
        android:id="@+id/list_recyclerview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="?attr/actionBarSize"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:spanCount="2"
        tools:itemCount="14"
        tools:layoutManager="android.support.v7.widget.GridLayoutManager"
        tools:listitem="@layout/layout_thermal_grid" 

        android:fadingEdgeLength="@dimen/pad_120dp"
        android:requiresFadingEdge="vertical" />
</RelativeLayout>

关于android - 如何仅在 Scrollview/Recyclerview 的底部添加淡入淡出边缘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62446951/

相关文章:

android - Facebook publish_action

java - SIGSEGV Android JNI 空方法

android - OpenGL ES 2.0 指定位置属性 vec3 或 vec4

Android 设备管理员 - 禁用未应用于(多用户) guest 帐户的相机

android - 可扩展布局与 recyclerview android

java - RecyclerView 不显示任何内容

iphone - iPhone 中的 UIScrollView?

android - 如何将多个 ViewPagers 放到一个 ScrollView 中?

ios - 如何使 SwiftUI 循环中的元素全屏显示?与 Apple 一样,当今的应用程序

android - 每当弹出键盘时,如何在软键盘上方自动向上滚动聊天消息(使用 recyclerview 而不是 ListView )?