【发布时间】:2015-09-21 17:07:51
【问题描述】:
我有以下布局:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
android:paddingBottom="?attr/actionBarSize"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Rest of the code there -->
</FrameLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/image_iv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7"
tools:ignore="ContentDescription" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<!-- FAB -->
<android.support.design.widget.FloatingActionButton
android:id="@+id/favorite_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:clickable="true"
android:src="@drawable/ic_star_rate"
app:layout_anchor="@id/container"
app:layout_anchorGravity="bottom|right" />
</android.support.design.widget.CoordinatorLayout>
观看以下视频:http://www.youtube.com/watch?v=kkWuh4UU6qM(抱歉,方向错误)。
在 Nexus 4 (5.1.1) CollapsingToolbarLayout 上工作正常,在 Galaxy S3 (4.4) 上却不行。
在 Galaxy S3 上滚动 NestedScrollView 的内容可以正常工作(卡片滚动到工具栏下方的顶部),// 在 Nexus 4 上滚动卡片的内容而不是卡片。 — 通过交换 NestedScrollView 和 AppBarLayout 位置来修复。
我使用构建工具 23.0.1。
如何解决?
【问题讨论】:
-
可能是NestedScrollView的bug。我尽量不使用它
-
AppBarLayout 应该是 CoordinatorLayout 的第一个孩子。如果与滚动视图一起使用,它将在内容上绘制自身。
-
@EugenPechanec 谢谢,解决了第二个问题。第一个仍然是实际的。
-
您可以将填充从 NestedScrollView 移动到其子视图。直接在 (Nested)ScrollView 上使用时,填充总是会出现问题。
android:adjustViewBounds="true"看起来很可疑。尝试指定一个固定的高度。分别尝试这两个建议,之后保持填充修复。
标签: android material-design android-toolbar androiddesignsupport android-collapsingtoolbarlayout