Skip to content Skip to sidebar Skip to footer

Toolbar Not Scrolling When Using Collapsing Toolbar Effect

I am using below layout to use collapsing toolbar effect but not able to expand toolbar.I want to expand the toolbar as given here for collapsing toolbar effect. https://guides.cod

Solution 1:

I suppose that the view with app:layout_behavior="@string/appbar_scrolling_view_behavior" has to be scrollable vertically, which ViewPager is not. I am not quite sure whether wrapping the ViewPager into some ScrollView would help. Most probably it would cause some problems with touch event handling. If the page within your ViewPager is scrollable, you should set the app:layout_behavior directly to its scrollable view but I am not sure this would work as expected either. The collapsing toolbar effect is not meant to work this way and it is not yet perfect even when used as intended.

Solution 2:

Use design support library http://android-developers.blogspot.in/2015/05/android-design-support-library.html

include this in build.gradle

compile'com.android.support:design:22.2.0'compile'com.android.support:appcompat-v7:22.2.+'

for recycler view include this also

compile'com.android.support:recyclerview-v7:22.2.0'

<!-- AppBarLayout allows your Toolbar and other views (such as tabs provided by TabLayout) 
    to react to scroll events in a sibling view marked with a ScrollingViewBehavior.--><android.support.design.widget.AppBarLayoutandroid:id="@+id/appbar"android:layout_width="match_parent"android:layout_height="wrap_content"android:fitsSystemWindows="true"><!-- specify tag app:layout_scrollFlags --><android.support.v7.widget.Toolbarandroid:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="?attr/actionBarSize"android:background="?attr/colorPrimary"app:layout_scrollFlags="scroll|enterAlways"/><!-- specify tag app:layout_scrollFlags --><android.support.design.widget.TabLayoutandroid:id="@+id/tabLayout"android:scrollbars="horizontal"android:layout_below="@+id/toolbar"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="?attr/colorPrimary"app:layout_scrollFlags="scroll|enterAlways"/><!--  app:layout_collapseMode="pin" will help to pin this view at top when scroll --><TextViewandroid:layout_width="match_parent"android:layout_height="50dp"android:text="Title"android:gravity="center"app:layout_collapseMode="pin" /></android.support.design.widget.AppBarLayout><!-- This will be your scrolling view. 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" tag connects this features --><android.support.v7.widget.RecyclerViewandroid:id="@+id/list"app:layout_behavior="@string/appbar_scrolling_view_behavior"android:layout_width="match_parent"android:layout_height="match_parent"></android.support.v7.widget.RecyclerView></android.support.design.widget.CoordinatorLayout>

Your activity should extend AppCompatActivity

publicclassYourActivityextendsAppCompatActivity {

    @OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.your_layout);

        //set toolbarToolbartoolbar= (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
    }

}

Your app theme should be like this

<resources><!-- Base application theme. --><stylename="AppTheme"parent="Theme.AppCompat.NoActionBar"></style></resources>

Post a Comment for "Toolbar Not Scrolling When Using Collapsing Toolbar Effect"