[英]Hiding textView below toolbar in coordinator layout
I'm working on creating a layout that works as follows: 我正在创建一个如下工作的布局:
where the toolbar is in the main_activity and the others are in an other xml file 工具栏在main_activity中,其他工具在另一个xml文件中
And when I scroll, I want to hide the textView in between top toolbar and recyclerView. 当我滚动时,我想将textView隐藏在顶部工具栏和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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.