带有选项卡和 ViewPager 的 AppBarLayout

我对TabLayoutand有问题AppBarLayout,因为我希望我的选项卡位于底部,而现在它们位于顶部,当我向上滚动时,它们会与图像一起隐藏。还有第二个问题 -AppBarLayout当我滚动文本时图像不会隐藏,它只会在我尝试scroll在顶部图像时隐藏/显示

<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:id="@+id/main_layout"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:fitsSystemWindows = "true"

    tools:context=".MainActivity">


    <android.support.design.widget.AppBarLayout

        android:id="@+id/main_appbar"

        android:layout_width="match_parent"

        android:layout_height="250dp"

        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

        android:fitsSystemWindows="true">



        <android.support.design.widget.CollapsingToolbarLayout

            android:id="@+id/main_collapsing"

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            app:layout_scrollFlags="scroll|exitUntilCollapsed"

            android:fitsSystemWindows="true"

            app:contentScrim="?attr/colorPrimary"

            app:expandedTitleMarginStart="48dp"

            app:expandedTitleMarginEnd="64dp">



            <ImageView

                android:id="@+id/main_backdrop"

                android:layout_width="match_parent"

                android:layout_height="match_parent"

                android:scaleType="centerCrop"

                android:fitsSystemWindows="true"

                android:src="@raw/test"

                app:layout_collapseMode="parallax"/>




            <android.support.v7.widget.Toolbar

                android:id="@+id/main_toolbar"

                android:layout_width="match_parent"

                android:layout_height="?attr/actionBarSize"

                app:layout_scrollFlags="scroll|enterAlways"

                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"

                app:layout_collapseMode="pin"/>



汪汪一只猫
浏览 216回答 3
3回答

侃侃尔雅

滚动视图不支持 Appbar 行为,将其更改为 NestedScrollView 并使用以下布局:&nbsp;<LinearLayout&nbsp;android:layout_width="match_parent"&nbsp;android:layout_height="wrap_content"&nbsp;android:orientation="vertical"&nbsp;app:layout_behavior="@string/appbar_scrolling_view_behavior">&nbsp; <android.support.design.widget.TabLayout&nbsp; android:id="@+id/sliding_tabs"&nbsp; android:layout_width="match_parent"&nbsp; android:layout_height="wrap_content"&nbsp; android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>&nbsp; &nbsp;<android.support.v4.view.ViewPager&nbsp; &nbsp; android:id="@+id/viewpager"&nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; android:layout_height="match_parent"/>&nbsp;</LinearLayout

慕姐8265434

尝试为您添加重力TabLayout:&nbsp; &nbsp; <android.support.design.widget.TabLayout&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/sliding_tabs"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_gravity="bottom"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; />编辑:为了在 CollapsingToolbarLayout 下方拥有 TabLayout,只需将其放入您的 ViewPager,如下所示:<android.support.v4.view.ViewPager&nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/viewpager"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; app:layout_behavior="@string/appbar_scrolling_view_behavior"><android.support.design.widget.TabLayout&nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/sliding_tabs"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>&nbsp;</android.support.v4.view.ViewPager>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java