我正在创建一个如下工作的布局:
工具栏位于main_activity中 其他人在另一个xml文件中
当我滚动时,我想在顶部工具栏和recyclerView之间隐藏textView。
答案 0 :(得分:0)
为什么不试试以下内容,这可能会有所帮助
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);
}
}
});
答案 1 :(得分:0)
这是主要的活动
<?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>