如何逐渐在Recyclerview滚动条上隐藏项目

时间:2018-10-10 17:09:59

标签: android android-studio android-recyclerview android-animation

我如何逐渐在recyclerview滚动条上隐藏项目

我想要这样的 Image

enter image description here

工具栏

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="55dp"
    android:background="@color/posts_toolbar"
    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp">

    <com.salah250.forvo.Funcations.TextViewFont
        android:id="@+id/txt_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/posts_title"
        android:textColor="@color/posts_title"
        android:textSize="18dp" />

</android.support.v7.widget.Toolbar>

活动帖子

<?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="@color/posts_main"
    android:orientation="vertical"
    tools:context=".Posts.PostsActivity">

    <include layout="@layout/toolbar_posts" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_posts"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:overScrollMode="never" />

</LinearLayout>

我看了之后才可以在这里发帖,我根本找不到任何谈论它的话题,我希望能对此有所想法。

1 个答案:

答案 0 :(得分:3)

您可以将渐变图像放在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="@color/posts_main"
    android:orientation="vertical"
    tools:context=".Posts.PostsActivity">

    <include layout="@layout/toolbar_posts" />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/rv_posts"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:overScrollMode="never" />

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:src="@drawable/gradient"/>

    <FrameLayout/>            

</LinearLayout>

@drawable/gradient.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle" >

    <gradient
    android:angle="270"
    android:endColor="#00FFFFFF"
    android:startColor="#302e43" />

</shape>

然后还在RecyclerView的标题中添加具有渐变高度的空白视图,以使最上面的项目不会褪色