Android 折叠工具栏布局+;TabLayout,奇怪的工具栏标题边距

Android 折叠工具栏布局+;TabLayout,奇怪的工具栏标题边距,android,android-collapsingtoolbarlayout,Android,Android Collapsingtoolbarlayout,我有一个srange工具栏标题行为,我怀疑它是否有效 倒塌: 扩展: 最奇怪的是 应用程序:titleMarginTop 对标题放置没有任何影响 以下是我的Xml: <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns

我有一个srange工具栏标题行为,我怀疑它是否有效

倒塌:

扩展:

最奇怪的是

应用程序:titleMarginTop

对标题放置没有任何影响

以下是我的Xml:

<?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:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.m360learning.app.activity.UserDetailsActivity">


    <android.support.design.widget.AppBarLayout
        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/collapse_toolbar"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:background="@drawable/background_navigation_drawer"
                app:layout_collapseMode="parallax">
                <ImageView
                    android:id="@+id/header"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:fitsSystemWindows="true"
                    android:scaleType="centerInside" />

            </RelativeLayout>


            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:gravity="top"
                android:minHeight="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"

                 />

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_gravity="bottom"
                app:tabIndicatorColor="@color/colorAccent" />

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

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

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />

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

而且它不会改变扩展的行为

------------最终编辑--更正

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        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/collapse_toolbar"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/background_navigation_drawer"
                android:fitsSystemWindows="true"
                android:paddingBottom="?attr/actionBarSize"
                android:paddingEnd="30dp"
                android:paddingLeft="30dp"
                android:paddingRight="30dp"
                android:paddingStart="30dp"
                app:layout_collapseMode="parallax">

                ......


            </RelativeLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:gravity="top"
                android:minHeight="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:titleMarginTop="15dp" />



        </android.support.design.widget.CollapsingToolbarLayout>
        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_gravity="bottom"
            android:background="?attr/colorPrimary"
            app:tabGravity="fill"
            app:tabIndicatorColor="#99FFFFFF"
            app:tabIndicatorHeight="6dp"
            app:tabMode="fixed" />

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

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />


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

......

我认为您的表格布局应该在折叠工具栏布局之外,而仍然在AppBarLayout内部:

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

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabIndicatorColor="@color/colorAccent" />

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

选项卡部分是应用程序栏的一部分,但不是工具栏的一部分。

答案是可以的,但不幸的是,如果我们想要透明视差
表格布局
背景,则不起作用。要使其正常工作,您需要执行以下操作:

  • expandedTitleMarginBottom
    添加到
    折叠工具栏布局
  • layout\u height
    设置为
    TabLayout
    作为常量值
  • layout\u marginBottom
    添加到
    Toolbar
    ,其值与
    TabLayout
    高度相同


为什么不将工具栏高度设置为
?attr/actionBarSize
?如果在工具栏折叠时这样做,则选项卡栏将显示在其上方而不是下方。折叠工具栏中的选项卡和工具栏应为actionBarSize,而不是我的选项卡已经在折叠工具栏中。工具栏大小似乎与折叠工具栏的大小相同。这就是为什么我强迫它大约是ActionBarSize的两倍。如果我这样做的话,我会添加一个屏幕截图。很好!我肯定我试过这个。。我更新了我的XML,你知道当工具栏扩展时,如何减少标题下的边距吗?不是随便的。工具栏中可能有文本视图的样式,但我在Theme.AppCompat中找不到它。我唯一能建议的另一件事是,在工具栏上调用
setSupportActionBar()
,然后在操作栏上调用
setCustomView()
,以设置一个文本视图,您可以在其中控制边距和垂直对齐。我建议你再发一个问题,让社区去思考一下。嗯,谢谢,我会这么做的,我会先自己探索一点