Android 安卓工具栏隐藏不';行不通
当我在Android 安卓工具栏隐藏不';行不通,android,android-toolbar,Android,Android Toolbar,当我在Fragment中滚动ListView时,我的工具栏不会隐藏/显示。 我用的是来自中国的样品 这是我的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.andro
Fragment
中滚动ListView
时,我的工具栏
不会隐藏/显示。
我用的是来自中国的样品
这是我的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.support.design.widget.AppBarLayout
android:id="@+id/home_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<include
layout="@layout/toolbar_layout"/>
<android.support.design.widget.TabLayout
android:id="@+id/home_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/home_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
添加工具栏布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
我可以运行此代码,但
工具栏
无法隐藏。如何隐藏/显示它?您应该向我们显示工具栏布局的代码。无论如何,您应该向工具栏
添加layout\u滚动标记
,如下所示:
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
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"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways|snap" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
工具栏实现没有问题
appbar_滚动_查看_行为不起作用的一个原因是,如果布局中存在被片段膨胀的不受支持的小部件。尝试将布局封装在嵌套的滚动视图中,例如
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity">
/* Your views */
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
/*你的观点*/
我通过可滚动布局中的NestedScrollView而不是ScrollView解决了相同的问题 张贴你的工具栏和布局。另外,您试图滚动的列表是否超出了您的屏幕大小?@Sevle补充道。是-测试列表太大(比屏幕大)),我看不出您的工具栏实现有任何问题。我只能推测,隐藏工具栏不支持包含片段listview的视图。(也许您将Listview封装在LinearLayout或简单的ScrollView中?)。尝试将ListView放在NestedScrollView下,并检查其是否有效。在任何情况下,如果你包含你的片段的布局xml,我可能会有更多的想法。@Sevle写作为回答你的想法,我接受你的回答NestedScrollView对我也不起作用,但RecyclerView似乎很好。对我不起作用-我添加了工具栏布局的代码。此外还添加了“| snap”。你好,Leonid,请参阅这篇文章,了解如何正确回答问题:
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity">
/* Your views */
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>