Reputation: 4867
CollapsingToolbarLayout | Scrolling and layout issues 2
I have been working with the Android Support Design Library
and successfully implemented the CoordinatorLayout
that causes the Toolbar
and TabLayout
to scroll out of view when scrolling. This works very well, so I figured I would try my luck with the new CollapsingToolbarLayout
.
In a seperate activity, I have been having issue-after-issue with implementing CollapsingToolbarLayout
. I am, as they say, close but no cigar.
I want to use 2 different fragments
ImageView
)I had built one example of this layout by myself, but could not get it working after many tries. Finally, I found this [enter image description here][5] and modified it to get to the point I am now
Note: I don't know if these are caused by 1 thing (dominoes effect), or if these are individual. Also, I have looked at quite a few related questions, but none seem to have any of these issues.
Scrollable Content
is shown above the Header ImageScrollable Content
is not anchored to the bottom of the Header Image
On Scrolling of Scrollable Content
it will scroll the Header Image
seemingly randomly of either:
Just right
and follows the speed of the finger (perfect)Too fast
and will animate the Header Image
off the screen by moving my finger the height of 1 line of textAlso on Scroll down
, the 2 above effects happen along with a 3rd effect
Instant
or Near instant
"animation" of showing the Header Image
at full widthEdit: These below are asked in another question!! The above had 1 simple fix
The CollapsingToolbarLayout
does not allow me to expand the Toolbar
to see the full Header Image
Top
is cut, but the bottom is visible.The Toolbar
is set to Pin
but it is hidden when scrolling
Header Image
should disappear<android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout>
<android.support.design.widget.CollapsingToolbarLayout>
<ImageView/> <!-- Will be a fragment later -->
<android.support.v7.widget.Toolbar/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView>
<fragment/> <!-- Not a scrolling fragment layout -->
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
<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:fitsSystemWindows="true">
<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.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="16dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|enterAlways">
<ImageView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/download"
android:scaleType="centerCrop" />
<android.support.v7.widget.Toolbar
android:id="@+id/anim_toolbar"
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="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/imageView1">
<fragment
android:id="@+id/detail"
android:name="<package>.<fragment_name>"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
1 2 3
4 5 6
Upvotes: 3
Views: 4728
Reputation: 199825
You need to add app:layout_behavior="@string/appbar_scrolling_view_behavior"
to your NestedScrollView
- this marks the class which should be positioned below the AppBarLayout
(and hence, below the CollapsingToolbarLayout
).
Upvotes: 7