Morton
Morton

Reputation: 5760

CoordinatorLayout with Framelayout is no working

I use tabLayout with three tabs in viewPager , i want to use CoordinatorLayout to hide and show my toolbar when scrolling. It's no working when i try it.

MainActivity layout: I had add app:layout_behavior="@string/appbar_scrolling_view_behavior" in my Framelayout , it's no working.

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="tw.idv.morton.mydailysugar.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolBar"
            app:contentInsetStart="0dp"
            android:layout_width="match_parent"
            android:layout_height="35dp"></android.support.v7.widget.Toolbar>

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

    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"></FrameLayout>

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

My tab one layout: I try to change ScrollView to android.support.v4.widget.NestedScrollView , it's still no working.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:paddingLeft="@dimen/appPadding"
    android:paddingRight="@dimen/appPadding"
    android:paddingTop="@dimen/appPadding"
    android:background="#ffffff"
    tools:context=".MyTabs.MyDailyInput">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    // here is lots of button and text and layout...    

    </ScrollView>


</LinearLayout>

Here is my tab layout setting:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    tools:context=".MyTabs.HomeTabs">

    <tw.idv.morton.mydailysugar.MyTabs.NoSwipingViewPager
        android:id="@+id/viewPagerDataReport"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <View
        android:background="@android:color/darker_gray"
        android:layout_width="match_parent"
        android:layout_height="1dp"/>

    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="55dp"
        android:clickable="true"
        style="@style/AppTabLayout"
        app:tabTextAppearance="@style/AppTabTextAppearance"
        android:background="@color/appColor"
        app:tabTextColor="@android:color/white"
        app:tabGravity="fill"/>
</LinearLayout>

I had add like app:layout_behavior="@string/appbar_scrolling_view_behavior" and android.support.v4.widget.NestedScrollView why its still no working ? Any help would be appreciated . Thanks in advance.

Upvotes: 0

Views: 1265

Answers (1)

Nick Asher
Nick Asher

Reputation: 756

That's because you haven't set the scroll flags in toolbar. Use the following code for your toolbar

<android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"/>

Further read more about scroll techniques here https://github.com/codepath/android_guides/wiki/Handling-Scrolls-with-CoordinatorLayout

Upvotes: 1

Related Questions