Android 协调布局不';不要隐藏操作栏
这让我快发疯了。两天来,我一直在努力完成这项工作,但没有取得任何进展。我希望有一个应用程序栏,当我向下滚动Android 协调布局不';不要隐藏操作栏,android,android-fragments,Android,Android Fragments,这让我快发疯了。两天来,我一直在努力完成这项工作,但没有取得任何进展。我希望有一个应用程序栏,当我向下滚动ViewPager时隐藏,当我向上滚动ViewPager时显示,这似乎是标准的方式 <android.support.design.widget.CoordinatorLayout android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_par
ViewPager
时隐藏,当我向上滚动ViewPager
时显示,这似乎是标准的方式
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways">
<android.support.design.widget.TabLayout
android:id="@+id/posts_pager_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:layout_collapseMode="pin">
</android.support.design.widget.TabLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/posts_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
viewpager包含一组片段,每个片段中都包含一个listview。我正在使用appcompat和22.2.0版的设计
我已将我的代码与此处的代码进行了比较:git@github.com:slidenerd/Android-Design-Support-Library-Demo.git,未发现重大差异。有人能帮忙吗?谢谢如果我没有用尽所有的选择,我不会发布这个 我做了一些测试,以下是我的发现: 原来的布局(没有
折叠工具栏布局
)更接近。我调整了您的布局并使用它进行了测试:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
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:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:layout_scrollFlags="scroll|enterAlways" />
<android.support.design.widget.TabLayout
android:id="@+id/posts_pager_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/posts_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
以下是要点:
必须有一个CoordinatorLayout
和另一个子布局AppBarLayout
必须具有AppBarLayout
工具栏和/或
表格布局
属性位于app:layout\u scrollFlags=“scroll | enterally”
工具栏和/或
表格布局上 无论哪个布局有
滚动标志(或两者都有),都将从视图中滚动出去。因此,我不知道您是否希望
滚动,而不是工具栏
,但无论哪种方式,您都可以控制行为表格布局
- 不能将
用作滚动视图。甚至在列表视图
片段中。添加ViewPager
属性没有任何区别 您必须使用app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”
或RecyclerView
。奇怪的是,我不需要NestedScrollView
上的RecyclerView
属性。这是在app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”
的ViewPager
子类中片段
折叠工具栏布局吗
?你能澄清一下“向上/向下滚动”你的ViewPager吗?你的意思是在ViewPager中左右滑动还是在ListView中上下滚动?@MarkusRubey向上/向下滚动将出现在ViewPager的ListView中。左右滚动可切换ViewPager中的当前项。我做了一些测试并为您输入了答案。>您必须使用RecyclerView或NestedScrollView。奇怪的是,我不需要RecyclerView上的app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”属性。这是ViewPager的Fragment子类的内部。嗯,让我测试一下。谢谢谢谢现在可以了。我需要做的就是从ListView
切换到RecyclerView
。你让我度过了一个最好的下午!