Java 在协调器布局中隐藏工具栏下方的文本视图
我正在创建一个布局,其工作原理如下:Java 在协调器布局中隐藏工具栏下方的文本视图,java,android,android-recyclerview,android-toolbar,android-coordinatorlayout,Java,Android,Android Recyclerview,Android Toolbar,Android Coordinatorlayout,我正在创建一个布局,其工作原理如下: 顶部的工具栏 顶部工具栏下方的文本视图(标题) 回收视图 钮扣 工具栏在主活动中的位置 其他的在另一个xml文件中 当我滚动时,我想将文本视图隐藏在顶部工具栏和recyclerView之间。为什么不试试下面的方法,可能会有帮助 myRecyclerview.addOnScrollListener(new RecyclerView.OnScrollListener(){ @Override public vo
- 顶部的工具栏
- 顶部工具栏下方的文本视图(标题)
- 回收视图
- 钮扣
当我滚动时,我想将文本视图隐藏在顶部工具栏和recyclerView之间。为什么不试试下面的方法,可能会有帮助
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);
}
}
});
这是主要的活动
<?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>
您能分享您的xml(布局)文件吗?谢谢,但它不起作用。您认为我的xml文件正确吗?是否进行了更改?用变量替换myRecyclerview
和myTextview
,并尝试使用我的答案中注释掉的布尔变量