CollapsingToolbarLayout&安培; NestedScrollView不一起工作 [英] CollapsingToolbarLayout & NestedScrollView don't work together
问题描述
我试图让 CollapsingToolbarLayout
与 NestedScrollView
工作,但它不遵循的滚动 NestedScrollView
正确。它移动时, NestedScrollView
到达顶部或底部一点点,但是这显然不是预期的行为。
呵呵,和 contentScrim
覆盖的ImageView
立即为好。
下面是发生了什么视频: https://youtu.be/1GlTJq5fd0U
和这里的XML:
< android.support.design.widget.CoordinatorLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:程序=http://schemas.android.com/apk/res-auto
的xmlns:工具=http://schemas.android.com/tools
机器人:ID =@ + ID / articleLayout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:fitsSystemWindows =真
工具:上下文=com.gmail.senokt16.bosphoruschronicle.ArticleActivity>
< android.support.design.widget.AppBarLayout
机器人:ID =@ + ID / articleAppBarLayout
机器人:layout_width =match_parent
机器人:layout_height =256dp
机器人:fitsSystemWindows =真正的> < android.support.design.widget.CollapsingToolbarLayout
机器人:ID =@ + ID / articleCollapsingToolbar
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:fitsSystemWindows =真
应用:contentScrim =@彩色/ primaryColor
应用:expandedTitleMarginEnd =64dp
应用:expandedTitleMarginStart =48dp
应用:layout_scrollFlags =滚动| exitUntilCollapsed
应用:toolbarId =@ + ID / article_app_bar> < ImageView的
机器人:ID =@ + ID / articleActivityImage
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:fitsSystemWindows =真
应用:layout_collapseMode =视差/> <包括
机器人:ID =@ + ID / article_app_bar
布局=@布局/ article_app_bar/>
< /android.support.design.widget.CollapsingToolbarLayout>
< /android.support.design.widget.AppBarLayout> < android.support.v4.widget.NestedScrollView
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_gravity =fill_vertical
机器人:fitsSystemWindows =真
应用:layout_behavior =@字符串/ appbar_scrolling_view_behavior
应用:layout_scrollFlags =滚动| enterAlways> <的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直
机器人:paddingTop =24dp> <的TextView
机器人:ID =@ + ID / articleActivityContents
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:paddingBottom会=30dp
机器人:paddingLeft =20dp
机器人:paddingRight =20dp
机器人:paddingTop =5DP/>
< / LinearLayout中>
< /android.support.v4.widget.NestedScrollView> < android.support.design.widget.FloatingActionButton
机器人:ID =@ + ID / articleFAB
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_margin =16DP
机器人:可点击=真
机器人:SRC =@机器人:可绘制/ ic_menu_share
应用:layout_anchor =@ ID / articleAppBarLayout
应用:layout_anchorGravity =底部|右|结束/>
< /android.support.design.widget.CoordinatorLayout>
我结束了一堆XML标签玩耍,不知道哪一个解决了这一问题,但这里的XML的最后一个版本:
< android.support.design.widget.CoordinatorLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:程序=http://schemas.android.com/apk/res-auto
的xmlns:工具=http://schemas.android.com/tools
机器人:ID =@ + ID / articleLayout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:fitsSystemWindows =真
工具:上下文=com.gmail.senokt16.bosphoruschronicle.ArticleActivity>
< android.support.design.widget.AppBarLayout
机器人:ID =@ + ID / articleAppBarLayout
机器人:layout_width =match_parent
机器人:layout_height =280dp
机器人:fitsSystemWindows =真
机器人:主题=@风格/ ThemeOverlay.AppCompat.Dark.ActionBar> < android.support.design.widget.CollapsingToolbarLayout
机器人:ID =@ + ID / articleCollapsingToolbar
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:fitsSystemWindows =真
应用:contentScrim =@彩色/ primaryColor
应用:expandedTitleMarginEnd =96dp
应用:layout_scrollFlags =滚动| exitUntilCollapsed> <查看
机器人:layout_width =match_parent
机器人:fitsSystemWindows =真
机器人:layout_height =match_parent
机器人:背景=@绘制/梯度
/>
< ImageView的
机器人:ID =@ + ID / articleActivityImage
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:fitsSystemWindows =真
应用:layout_collapseMode =视差
机器人:scaleType =centerCrop/> < android.support.v7.widget.Toolbar
机器人:ID =@ + ID / article_app_bar
机器人:layout_width =match_parent
机器人:layout_height =?ATTR / actionBarSize
应用:layout_collapseMode =针/>
< /android.support.design.widget.CollapsingToolbarLayout>
< /android.support.design.widget.AppBarLayout> < android.support.v4.widget.NestedScrollView
机器人:layout_width =match_parent
机器人:layout_height =match_parent
应用:layout_behavior =@字符串/ appbar_scrolling_view_behavior> <的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直
机器人:paddingTop =24dp> <的TextView
机器人:ID =@ + ID / articleActivityContents
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:paddingBottom会=30dp
机器人:paddingLeft =20dp
机器人:paddingRight =20dp
机器人:paddingTop =5DP/>
< / LinearLayout中>
< /android.support.v4.widget.NestedScrollView> < android.support.design.widget.FloatingActionButton
机器人:ID =@ + ID / articleFAB
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_margin =16DP
机器人:可点击=真
机器人:SRC =@机器人:可绘制/ ic_menu_share
应用:layout_anchor =@ ID / articleAppBarLayout
应用:layout_anchorGravity =底部|右|结束/>
< /android.support.design.widget.CoordinatorLayout>
I'm trying to make CollapsingToolbarLayout
work with NestedScrollView
, but it doesn't follow the scrolling of NestedScrollView
correctly. It moves a little bit when the NestedScrollView
reaches the top or bottom end, but that's clearly not the intended behavior.
Oh, and the contentScrim
covers the ImageView
immediately as well.
Here's a video of what happens: https://youtu.be/1GlTJq5fd0U
And here's the xml:
<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:id="@+id/articleLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.gmail.senokt16.bosphoruschronicle.ArticleActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/articleAppBarLayout"
android:layout_width="match_parent"
android:layout_height="256dp"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/articleCollapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="@color/primaryColor"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="@+id/article_app_bar">
<ImageView
android:id="@+id/articleActivityImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax" />
<include
android:id="@+id/article_app_bar"
layout="@layout/article_app_bar" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
android:fitsSystemWindows="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_scrollFlags="scroll|enterAlways">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="24dp">
<TextView
android:id="@+id/articleActivityContents"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="30dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="5dp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/articleFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="@android:drawable/ic_menu_share"
app:layout_anchor="@id/articleAppBarLayout"
app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>
I ended up playing around with a bunch of xml tags and don't know which one fixed the problem, but here's the last version of the xml:
<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:id="@+id/articleLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.gmail.senokt16.bosphoruschronicle.ArticleActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/articleAppBarLayout"
android:layout_width="match_parent"
android:layout_height="280dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/articleCollapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="@color/primaryColor"
app:expandedTitleMarginEnd="96dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<View
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="match_parent"
android:background="@drawable/gradient"
/>
<ImageView
android:id="@+id/articleActivityImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
android:scaleType="centerCrop"/>
<android.support.v7.widget.Toolbar
android:id="@+id/article_app_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="24dp">
<TextView
android:id="@+id/articleActivityContents"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="30dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="5dp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/articleFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="@android:drawable/ic_menu_share"
app:layout_anchor="@id/articleAppBarLayout"
app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>
这篇关于CollapsingToolbarLayout&安培; NestedScrollView不一起工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!