0

I have,in my code, only one activity and many fragments. The structure is this one :

<android.support.v4.widget.DrawerLayout>

    <android.support.design.widget.CoordinatorLayout>

        <android.support.design.widget.AppBarLayout>

            <android.support.design.widget.CollapsingToolbarLayout>
                <ImageView/>
                <android.support.v7.widget.Toolbar/>
            </android.support.design.widget.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>

        <FrameLayout/>

    <android.support.design.widget.CoordinatorLayout>

    <android.support.design.widget.NavigationView/>

</android.support.v4.widget.DrawerLayout>

and

compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'

I don't need the collapsing toolbar in all fragments but I prefered to do that instead of putting a appbarlayout in each fragment.

The problem is when I launch my app :

1) I am on a fragment where the collapsing toolbar is not usefull( I don't have scrolling content) BUT I can still expand the collapsing toolbar if I scroll on the toolbar (This is the issue...).

2) Now,I go in a fragment with scrolling content and I expand the collapsing toolbar with a recyclerview , the collapsing toolbar works normally.

3) I want to repeat the bug of 1), the bug is not present anymore. Like scrolling with a recyclerview has solved the bug? The collapsing toolbar does not expand if I scroll on the toolbar. And I would like it to be like till the launch of the app. I don't won't to go on a fragment scrolling content to disable this bug.

You can see this gif which represent what I'm talking about via GIPHY

Can you help me? :)

laurent512
  • 11
  • 1
  • 2

1 Answers1

0

If you want to change the scroll behavior you can do that programmatically by changing the Scroll Flags on the AppBarLayout.LayoutParams of the CollapsingToolbarLayout.

CollapsingToolbarLayout ctl= (CollapsingToolbarLayout) findViewById(R.id.collapsing_appbar);
AppBarLayout.LayoutParams params = ctl.getLayoutParams();
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);//or a combination of flags
ctl.setLayoutParams(params);

Another trick to make the CollapsingToolbarLayout scroll 'with no scrolling content' is to put 'your layout' in a NestedScrollView and set a *1000dp min height value to the child of the NestedScrollView ('your layout').

android:minHeight="1000dp"

Layout:

<android.support.v4.widget.NestedScrollView
app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <!--your layout-->
    <FrameLayout android:minHeight="1000dp"/>

</android.support.v4.widget.NestedScrollView>

*SupportDesignDemos example here: https://github.com/android/platform_development/blob/master/samples/SupportDesignDemos/res/layout/include_appbar_scrollview.xml

TouchBoarder
  • 6,422
  • 2
  • 52
  • 60
  • Actually I have already tried your first solution before and it fixed the collapsing toolbar to it's maximum. My goal is to have the same behavior as if the bar did not exist :) – laurent512 Nov 22 '15 at 18:33
  • @laurent512 you want the CollapsingToolbarLayout to act as a regular "ActionBar"? have you tried setting the height of the AppBarLayout to the default ActionBar height programmatically? – TouchBoarder Nov 22 '15 at 21:07
  • Did you see my gif? I would like to understand why this behavior happens :/ I don't see why the collapsing toolbar expand when we scroll on itself the first time and after no... :/ And do you have a good link to set the height programmatically? :) – laurent512 Nov 23 '15 at 11:41
  • Because my final goal is exactly : let's do like this collapsing toolbar didn't exist on this fragment. – laurent512 Nov 23 '15 at 12:35