CoordinatorLayout + TabView + AnimateView(From Top)
Asked Answered
G

1

12

Yesterday I am playing with CoordinatorLayout with TabView

1) What is my target ?

  • CoordinatorLayout with TabView
  • When I scroll up at that time One View As show in .GIF move down.
  • and Stick on the Top of the TabView (inside AppBar).

enter image description here

2) Where I reached ?

  • CoordinatorLayout with TabView with pretty scrolling.
  • TabView with Appbar Stop Scrolling At Top after Then Scroll RecyclerView.

enter image description here

3) Where I stuck ?

  • When I scroll Up One View Scroll Down but TabView Stick At Top not like 1st gif.

4) Code snippet

  • Xml file

    <android.support.design.widget.AppBarLayout
        android:id="@+id/main.appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
        <!--- ADD TAB_LAYOUT HERE -->
    
    
        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/main.collapsing"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll">
    
            <ImageView
                android:id="@+id/main.backdrop"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                android:src="@drawable/abc"
                app:layout_collapseMode="none" />
    
    
            <!-- ADD ANY THING THAT GETS SCROLLED ALL THE WAY UP WITH TOOLBAR -->
        </android.support.design.widget.CollapsingToolbarLayout>
    
    
        <!-- our tablayout to display tabs  -->
        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            android:minHeight="?attr/actionBarSize"
    
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
    
    
    </android.support.design.widget.AppBarLayout>
    
    
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    

  • Java file (move upper view down code)

    AppBarLayout ab = (AppBarLayout) findViewById(R.id.main_appbar);ab.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
    
            int ScrollStart = (ab.getHeight() - tabLayout.getHeight() - llTop.getHeight() - llTop.getHeight());
            int scrollStop = (ab.getHeight() - tabLayout.getHeight() - llTop.getHeight());
            if ((-verticalOffset) > ScrollStart && (-verticalOffset) < scrollStop) {
                llTop.setVisibility(View.VISIBLE);
                llTop.setTranslationY(((-verticalOffset) - ScrollStart) - llTop.getHeight());
                Log.e("point", "" + ((-verticalOffset) - ScrollStart));
    
            } else if ((-verticalOffset) >= scrollStop) {
                llTop.setVisibility(View.VISIBLE);
            } else {
                llTop.setVisibility(View.INVISIBLE);
            }
    
    
        }
    });
    
Gummy answered 28/4, 2017 at 6:6 Comment(4)
add tab layout inside collapsing toolbar layoutAleron
then it will hide when i scrollGummy
#22648924 this might solve itPluto
Due to differnet scroll behaviour sticky header not work i thing because of TabView scroll up that time layout scroll down.Gummy
P
6

It's tricky little bit..

just try to setMinimumHeight of your CollapsingToolbarLayout like this way and do let me know.

CollapsingToolbarLayout layoutCollapsing = (CollapsingToolbarLayout) rootView.findViewById(R.id.layoutCollapsing);
layoutCollapsing.setMinimumHeight(120); 

here calculate your minimum height as per your need and set it in place of setMinimumHeight(120) value.

Pharr answered 1/5, 2017 at 6:37 Comment(2)
Thank you so much .. after 2 days i can solve it. with add just one line android:minHeight="". I accept your ans :)Gummy
your wc ..:) any time and every time .Pharr

© 2022 - 2024 — McMap. All rights reserved.