滚动时淡出自定义视图

时间:2015-10-14 01:27:44

标签: android animation

工具栏下有一个自定义固定搜索视图:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="match_parent"
         android:layout_height="match_parent">

<com.mobium.reference.views.AdvancedSearchView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

<android.support.v7.widget.RecyclerView
    android:id="@+id/catalogItems"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="2dp"
    android:layout_marginTop="?attr/actionBarSize"
    android:scrollbars="vertical"/>

我想在滚动回收器视图的同时为它制作淡出动画(Google I / O使用工具栏)。

enter image description here

可能有任何办法用设计支持库来做,不知道如何。

我会很高兴任何提示,谢谢!

2 个答案:

答案 0 :(得分:0)

recyclerview hide on scroll sample  第3部分对你很有用。

答案 1 :(得分:0)

添加滚动侦听器以切换可见性:

recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        if(dy > 0){
            searchView.setVisibility(View.GONE);
        }
        else{
            searchView.setVisibility(View.VISIBLE);
        }
    }
});

animateLayoutChanges为观看次数设置动画:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true">

与问题无关:

对您的保证金问题进行先发制人的打击。如果您希望recyclerView填写搜索框占用的区域,您应该使用paddingTop并将clipToPadding设置为false:

<android.support.v7.widget.RecyclerView
    android:id="@+id/catalogItems"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="?attr/actionBarSize"
    android:clipToPadding="false"/>
相关问题