【发布时间】:2015-09-07 06:59:19
【问题描述】:
我有以下布局:一个抽屉,主要内容视图有一个 AppBarLayout、RecyclerView 和一个 TextView。当我滚动回收器时,工具栏被正确隐藏。
但是,我有一个用例:当回收站中的所有项目都被移除时,我将其可见性设置为“已消失”,并设置一个带有适当消息的 TextView。如果在工具栏隐藏时这样做,用户将无法再次看到工具栏。
是否可以以编程方式使工具栏完全显示?每当显示 TextView 而不是 RecyclerView 时,我都会这样做。
这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
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:animateLayoutChanges="true">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/test_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<TextView
android:id="@+id/empty_test_list_info_label"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="@dimen/spacing_big"
android:textAppearance="?android:attr/textAppearanceLarge"
android:visibility="gone"/>
</android.support.design.widget.CoordinatorLayout>
<RelativeLayout
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="?android:attr/windowBackground"
android:elevation="10dp"/>
</android.support.v4.widget.DrawerLayout>
顺便说一句,由于某种原因,如果我将 AppBarLayour 放在 RecyclerView 之后,正如所有教程似乎都显示的那样,它会隐藏列表中最顶层的项目。只有在它上面时它才能正常工作。
【问题讨论】:
-
您找到解决方案了吗?我有同样的问题..
-
@GennadiiSaprykin - 不,我没有,抱歉。我想最后我实现了一些不同的东西,但是已经很长时间了,我不知道它是什么,并且从那时起改变了项目。
标签: android android-design-library