【问题标题】:Add app bar scrolling view behavior to customer views in CoordinatorLayout将应用栏滚动视图行为添加到 CoordinatorLayout 中的客户视图
【发布时间】:2017-01-29 06:20:08
【问题描述】:

我对@9​​87654323@ 有疑问。 这是我的 xml 代码:

<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"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme.AppBarOverlay"
    app:elevation="0dp">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:statusBarScrim="@android:color/transparent">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:scaleType="fitXY"
            android:src="@mipmap/bg"/>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/AppTheme.PopupOverlay"/>

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

    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:layout_scrollFlags="scroll">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            android:padding="10dp"
            android:text="I wanna scroll up to behind of the toolbar"
            android:textColor="#333"/>
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:tabGravity="fill"
        app:tabIndicatorColor="@color/colorPrimary"
        app:tabIndicatorHeight="2dp"
        app:tabMode="fixed"
        app:tabSelectedTextColor="@color/colorPrimary"
        app:tabTextColor="@android:color/darker_gray"/>

    <!-- ViewPager -->
    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

我想滚动TextView util Toolbar 覆盖它,但它不起作用。 现在它的效果是这样的。 Effect Gif

我的目标就是这个效果。 enter image description here

我该怎么办?

【问题讨论】:

    标签: android scroll behavior android-coordinatorlayout appbar


    【解决方案1】:

    只需将TabLayout 放入AppBarLayout

    <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"
    android:fitsSystemWindows="true">
    
    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:elevation="0dp">
    
        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="@dimen/app_bar_height"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:statusBarScrim="@android:color/transparent">
    
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="fitXY"
                android:src="@mipmap/bg"/>
    
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay"/>
    
        </android.support.design.widget.CollapsingToolbarLayout>
    
        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll">
    
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                android:padding="10dp"
                android:text="I wanna scroll up to behind of the toolbar"
                android:textColor="#333"/>
        </android.support.design.widget.CollapsingToolbarLayout>
    
        <android.support.design.widget.TabLayout
            android:id="@+id/tab_layout"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:tabGravity="fill"
            app:tabIndicatorColor="@color/colorPrimary"
            app:tabIndicatorHeight="2dp"
            app:tabMode="fixed"
            app:tabSelectedTextColor="@color/colorPrimary"
            app:tabTextColor="@android:color/darker_gray"/>
    
    </android.support.design.widget.AppBarLayout>
    
    <!-- ViewPager -->
        <android.support.v4.view.ViewPager
            android:id="@+id/view_pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    
    <android.support.design.widget.CoordinatorLayout
    

    【讨论】:

      【解决方案2】:

      请试试这个:-

      <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"
          android:fitsSystemWindows="true">
      
          <android.support.design.widget.AppBarLayout
              android:id="@+id/app_bar"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:fitsSystemWindows="true"
              android:theme="@style/AppTheme.AppBarOverlay"
              app:elevation="0dp">
      
              <android.support.design.widget.CollapsingToolbarLayout
                  android:id="@+id/toolbar_layout"
                  android:layout_width="match_parent"
                  android:layout_height="@dimen/app_bar_height"
                  android:fitsSystemWindows="true"
                  app:contentScrim="?attr/colorPrimary"
                  app:layout_scrollFlags="scroll|snap"
                  app:statusBarScrim="@android:color/transparent">
      
                  <ImageView
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      android:fitsSystemWindows="true"
                      android:scaleType="fitXY"
                      android:src="@mipmap/bg"/>
      
                  <android.support.v7.widget.Toolbar
                      android:id="@+id/toolbar"
                      android:layout_width="match_parent"
                      android:layout_height="?attr/actionBarSize"
                      app:layout_collapseMode="pin"
                      app:popupTheme="@style/AppTheme.PopupOverlay"/>
      
              </android.support.design.widget.CollapsingToolbarLayout>
      
              <TextView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:background="@android:color/white"
                  android:padding="10dp"
                  app:layout_scrollFlags="scroll|snap"
                  android:text="I wanna scroll up to behind of the toolbar"
                  android:textColor="#333"/>
      
          </android.support.design.widget.AppBarLayout>
      
          <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical"
              app:layout_behavior="@string/appbar_scrolling_view_behavior">
      
              <android.support.design.widget.TabLayout
                  android:id="@+id/tab_layout"
                  android:layout_width="match_parent"
                  android:layout_height="?attr/actionBarSize"
                  app:tabGravity="fill"
                  app:tabIndicatorColor="@color/colorPrimary"
                  app:tabIndicatorHeight="2dp"
                  app:tabMode="fixed"
                  app:tabSelectedTextColor="@color/colorPrimary"
                  app:tabTextColor="@android:color/darker_gray"/>
      
              <!-- ViewPager -->
              <android.support.v4.view.ViewPager
                  android:id="@+id/view_pager"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"/>
      
          </LinearLayout>
      </android.support.design.widget.CoordinatorLayout>
      

      【讨论】:

        猜你喜欢
        • 2015-12-04
        • 1970-01-01
        • 1970-01-01
        • 2017-06-04
        • 2012-07-19
        • 2014-09-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多