Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoordinatorLayout + TabView + AnimateView(From Top)

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);
            }
    
    
        }
    });
    
like image 335
Vishal Patel Avatar asked Apr 28 '17 06:04

Vishal Patel


1 Answers

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.

like image 185
Radhey Avatar answered Nov 13 '22 00:11

Radhey