【发布时间】:2016-07-04 14:41:32
【问题描述】:
我有一个我希望始终固定在顶部的 TabLayout,还有一个下方的 Toolbar,当视图滚动时,它会向上滚动到 TabLayout。
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
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"
tools:context=".main.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:animateLayoutChanges="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView2"
android:src="@drawable/music_content"
android:contentDescription="@string/image_chooser_title"
/>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
你可以在这里看到我已经设置了工具栏
app:layout_scrollFlags="scroll|enterAlways"
并且不为上面的 TabLayout 设置任何滚动标志,因为我希望它保持固定。但是,使用这些设置,AppBarLayout 根本不会滚动。如果我向 TabLayout 添加滚动标志,那么它们都会滚动,并且 TabLayout 不会保持固定。有没有办法让 TabLayout 保持固定,而下面的工具栏向上滚动“屏幕外”?
如有需要可提供图片
【问题讨论】:
标签: android android-support-library android-toolbar android-design-library android-appbarlayout