2
如何在我的情況下滾動時隱藏工具欄?我有抽屜和嵌套片段的活動。在頁面中滾動時,我需要隱藏工具欄。那是怎麼回事?請幫幫我。如何在滾動片段時隱藏工具欄?
上傳:對不起,我的英語請。
活動佈局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/app_nav_header_main"
app:menu="@menu/main_drawer" />
</android.support.v4.widget.DrawerLayout>
app_bar_main.xml
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
content_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/app_bar_main"/>
片段與TabLayout和ViewPager:
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/flipper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
layout="@layout/layout_please_wait"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<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="2dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/AppTheme.AppBarOverlay"
app:tabIndicatorColor="@android:color/white" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</LinearLayout>
<include
layout="@layout/layout_no_internet"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</ViewFlipper>
頁片段:
<?xml version="1.0" encoding="utf-8"?>
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/flipper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/layout_please_wait" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/refresh"
android:layout_margin="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/newsList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="@android:color/transparent"
android:divider="@null"
android:dividerHeight="10dp"
android:listSelector="@android:color/transparent" />
</android.support.v4.widget.SwipeRefreshLayout>
<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
layout="@layout/layout_news_empty" />
<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
layout="@layout/layout_no_internet" />
</ViewFlipper>
在這裏的問題看起來像它有很好的例子,應該與在答案中描述的一個小修復工作:http://stackoverflow.com/questions/33132908/drawerlayout-collapsingtoolbar-fragments-toolbar-wont-collapse-or -show-ima –
@Daniel Nugent,thx。但這不適合我。也許是因爲我在片段中使用ListView?我只是添加應用程序:layout_collapseMode =「pin」,但不會讓我暫停:( – GPPSoft
建議。嘗試將該選項卡放在此https://github.com/chrisbanes/cheesesquare示例中。 – razzledazzle