【问题标题】:Android Tabs (within tabs there should be scroll view) with collapse header带有折叠标题的 Android 选项卡(在选项卡内应该有滚动视图)
【发布时间】:2016-04-16 14:49:06
【问题描述】:

带有折叠标题的 Android 选项卡,此标题位于将显示屏幕的操作栏下方,因此选项卡几乎位于布局的中心 所以首先我需要滚动标题,然后在达到某个高度后,所选选项卡中的滚动视图应该滚动。 请从以下链接下载 zip 文件 http://www.filedropper.com/profilescreenimp2

【问题讨论】:

    标签: android tabs header scrollview collapse


    【解决方案1】:

    让你的layout 如下:

    <?xml version="1.0" encoding="utf-8"?>
    

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:layout_height="wrap_content">
    
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"
            android:minHeight="?attr/actionBarSize"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:layout_scrollFlags="scroll|enterAlways">
    
            <TextView
                android:id="@+id/toolbar_title"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:textStyle="bold"
                style="@android:style/TextAppearance.Medium"
                android:text="Toolbar Title" />
    
    
        </android.support.v7.widget.Toolbar>
    
        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"
            app:tabGravity="fill"
            app:tabIndicatorColor="@android:color/white"
            app:tabMode="fixed" />
    </android.support.design.widget.AppBarLayout>
    
    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    

    【讨论】:

    • 您好,感谢您的回复,您能否帮助您更深入地实现此功能
    • @Logic,我想他想要一个折叠的标题。需要一个 CollapsingToolbarLayout。
    • @user3614958,如果用户向上滑动,协调器布局会隐藏工具栏
    • 嗨朋友们,我分享了一个链接,您可以在其中下载该 zip 文件并检查。共享代码适用于列表视图,但无法在滚动视图上运行
    【解决方案2】:
    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/homeCoordinator"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">
    
        <android.support.design.widget.AppBarLayout
            android:id="@+id/homeAppBarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    
            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/homeCollapseToolbar"
                android:layout_width="match_parent"
                android:layout_height="350dp"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
    
                //This can be changed to ImageView
                <com.daimajia.slider.library.SliderLayout
                    android:id="@+id/homeSliderLayout"
                    app:layout_collapseMode="parallax"
                    android:fitsSystemWindows="true"
                    android:layout_width="match_parent"
                    android:layout_height="350dp"/>
    
                <android.support.v7.widget.Toolbar
                    android:id="@+id/homeToolbar"
                    android:title=""
                    android:layout_width="match_parent"
                    android:layout_height="115dp"
                    android:gravity="top"
                    android:minHeight="?attr/actionBarSize"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    app:titleMarginTop="15dp" >
    
                    <ImageView
                        android:src="@drawable/ic_logo"
                        android:paddingLeft="10dp"
                        android:layout_gravity="center|top"
                        android:layout_width="wrap_content"
                        android:layout_height="35dp" />
    
                </android.support.v7.widget.Toolbar>
    
                <android.support.design.widget.TabLayout
                    android:id="@+id/homeTabLayout"
                    android:layout_marginBottom="15dp"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:layout_gravity="bottom"
                    app:tabGravity="center"
                    app:tabIndicatorColor="@color/colorAccent" />
    
            </android.support.design.widget.CollapsingToolbarLayout>
    
        </android.support.design.widget.AppBarLayout>
    
        <android.support.v4.view.ViewPager
            android:id="@+id/homeViewPager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    
    </android.support.design.widget.CoordinatorLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-28
      • 2020-06-21
      • 1970-01-01
      • 2016-11-08
      相关资源
      最近更新 更多