【发布时间】:2015-12-21 22:43:03
【问题描述】:
所以,我有这个使用CoordinatorLayout 在其下方显示工具栏和选项卡的主要活动布局:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
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"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="0dp"
local:layout_scrollFlags="scroll|enterAlways"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
local:tabMode="fixed"
local:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="@drawable/header_shadow"
local:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
然后我有 2 个片段布局,每个布局用于我将拥有的 2 个选项卡中的每一个。一个片段在其内容上显示ListView:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="@drawable/header_shadow"
tools:context=".StationsFragment">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<ListView
android:id="@+id/stations_listview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
当我滚动上面的列表视图时,我希望我的工具栏隐藏起来,我拥有的代码应该没问题,至少从我在answer 中读到的内容来看,但它不起作用。目前我试图从片段活动中删除FrameLayout,但这并没有解决问题。我考虑过对列表视图中的滚动事件进行硬编码,但如果可能的话,我真的希望它能够在没有代码的情况下工作..
提前致谢。
【问题讨论】:
-
嗯,试试你的xml中的layout_scrollFlags="scroll|enterAlwaysCollapsed"
-
@Coeus 不起作用:/,感谢您的回答
标签: android listview android-tabs