2

enter image description hereI am using requiresFadingEdge=true for adding fading effect at the bottom but the problem is it also shows fading effect at the top? How do I disable the fading effect at the top while scrolling down?

I have attached an scapshot of the screen at the bottom.

<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>
user9683713
  • 185
  • 2
  • 13

1 Answers1

5

You can use something like this:

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

    override fun getTopFadingEdgeStrength() = 0f
}

and then in your layout file:

<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>
mklkj
  • 300
  • 4
  • 8
  • FYI: This solution introduces small bug, as it overwrites default `defStyleAttrs` which has value R.attr.recyclerViewStyle, not 0. The `JvmOverloads` on view's constructor usually leads to such mistakes, so my recommendation would be to define just the two-argument one, and not use the `JvmOverload` annotation – cycki Mar 01 '22 at 11:46