2

Hello i am using collapsible layout and I want the behaviour of layout to change according to my scroll event as shown in the image:

  1. This is the by default image with list view and when user scrolls, the top layout should change and look like the one in second image.

First image

Second image

How should I achieve this kind of behaviour using collapsible layout.

Murtaza Khursheed Hussain
  • 15,176
  • 7
  • 58
  • 83

2 Answers2

0

you just add TabLayout under the toolbar like below

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:background="@color/colorPrimary"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"/>
<android.support.design.widget.TabLayout
    android:id="@+id/tabLayoutactivity_mainId"
    android:layout_below="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
Sam
  • 45
  • 1
  • 8
  • i dont want tab layout . Tab layout is going to remain the same but toolbar is getting replaced see the second image. – Suraj Jorwekar Sep 26 '16 at 06:29
  • i cant understand what you saying.., am using the above layout for one of my appliction development – Sam Sep 26 '16 at 06:33
0

Try to override this acording to your need. You can set layouts making visible/hide components in CollapsableToolbar.

 appbar = (AppBarLayout) findViewById(R.id.appbar);
    header = (Toolbar) findViewById(R.id.toolbar);

    appbar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
                private State state;

                @Override
                public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                    if (verticalOffset == 0) {
                        if (state != State.EXPANDED) {
                            collapsingToolbar.setTitleEnabled(false);
                           // do something here
                        }
                        state = State.EXPANDED;
                    } else if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()) {
                        if (state != State.COLLAPSED) {
                            collapsingToolbar.setTitle("All Jobs ");
                            collapsingToolbar.setTitleEnabled(true);

    //                  do something here      header.setBackgroundDrawable(ContextCompat.getDrawable(this, R.drawable.actionbar_gradient));
    //                        collapsingToolbar.setContentScrim(ContextCompat.getDrawable(this, R.drawable.actionbar_gradient));
                            collapsingToolbar.setContentScrim(ContextCompat.getDrawable(this, R.drawable.actionbar_bg));

    //                        collapsingToolbar.setBackgroundDrawable(ContextCompat.getDrawable(this, R.drawable.actionbar_bg));

                        }
                        state = State.COLLAPSED;
                    } else {
                        if (state == State.IDLE) {
                            collapsingToolbar.setTitleEnabled(false);
                            container.setVisibility(View.VISIBLE);
                        }
                        state = State.IDLE;
                    }
                }
            });

It worked for me try it....

Preetika Kaur
  • 1,991
  • 2
  • 16
  • 23