简体   繁体   中英

Hiding textView below toolbar in coordinator layout

I'm working on creating a layout that works as follows:

  • Toolbar at the top
  • textView(a title) below top toolbar
  • RecyclerView
  • button

where the toolbar is in the main_activity and the others are in an other xml file

And when I scroll, I want to hide the textView in between top toolbar and recyclerView.

why don't try the following, it might help

myRecyclerview.addOnScrollListener(new RecyclerView.OnScrollListener(){
            @Override
            public void onScrolled(RecyclerView rv, int dx, int dy) {
                //boolean hasStarted = state == rv.SCROLL_STATE_DRAGGING; //Scrollbar is MOVING
                //boolean hasEnded = state == rv.SCROLL_STATE_IDLE;       //ScrollBar is NOT MOVING
                //boolean isStopping = state == rv.SCROLL_STATE_SETTLING; //Scrollbar is STOPPING
                if(dy > 0){
                   myTextview.setVisibility(View.VISIBLE);
                }
            }
        });

and this is the main activity

<?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout
        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:fitsSystemWindows="true"
        >



        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            >


            <FrameLayout
                android:id="@+id/toolbar_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:layout_gravity="center"
                    app:titleMarginStart="10dp"



                <com.miguelcatalan.materialsearchview.MaterialSearchView
                    android:id="@+id/search_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"                   
                    android:inputType="textAutoCorrect"
                    app:searchBackIcon="@drawable/ic_back_arrow"
                    app:searchVoiceIcon="@drawable/ic_voice_black"
                    />

            </FrameLayout>

        </android.support.design.widget.AppBarLayout>
    </android.support.design.widget.CoordinatorLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM