在AppBarLayout

时间:2018-07-23 22:40:20

标签: android

过去一天,我一直在尝试解决UI问题。为了使我的TabLayout透明,我需要将其移动到AppBar布局之外,当我这样做时,它会变得透明,但是在过程中它与工具栏重叠。像这样(请参考图片):

enter image description here

这是我的布局:

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

<!-- app_bar height @dimen/detail_backdrop_height -->
<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapse_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:contentScrim="@color/colorPrimary"
        app:expandedTitleMarginTop="120dp"
        app:expandedTitleGravity="center|bottom"
        app:expandedTitleTextAppearance="@style/TransparentText">

        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:alpha="0.4"
            app:layout_collapseMode="parallax" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_collapseMode="parallax"
            app:layout_anchor="@+id/app_bar">

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/cover_image"
                android:layout_width="90dp"
                android:layout_height="90dp"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="50dp"
                app:civ_border_color="@android:color/black"
                app:civ_border_width="1dp" />

            <LinearLayout
                android:id="@+id/header_text_layout"
                android:layout_below="@id/cover_image"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/game_title"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="Game title"
                    android:gravity="center"
                    android:textColor="@android:color/white"
                    android:textSize="24sp"/>

                <TextView
                    android:id="@+id/developer_txt"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="Developer"
                    android:gravity="center"
                    android:textColor="@android:color/white"
                    android:textSize="14sp"/>

                <TextView
                    android:id="@+id/publisher_txt"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="Publisher"
                    android:gravity="center"
                    android:textColor="@android:color/white"
                    android:textSize="14sp"/>
            </LinearLayout>

        </RelativeLayout>

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

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

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

<android.support.design.widget.TabLayout
    android:id="@+id/tab_layout"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/actionBarSize"
    android:background="@android:color/transparent"
    app:layout_scrollFlags="scroll|enterAlways"
    app:tabGravity="fill"
    app:tabMode="fixed"/>

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

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

</FrameLayout>

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

我想要的是我应用栏下方的透明布局。谢谢!

1 个答案:

答案 0 :(得分:0)

要显示背景,您需要在root的所有TabLayout上放置透明度。

示例:

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme"
    android:background="@android:color/transparent">

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

    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent">

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

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

<android.support.v4.view.ViewPager
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/appBarLayout">

</android.support.v4.view.ViewPager>

否则,您的TabLayout是透明的,而不是您的AppBarLayout,因此它们显示的是背景(AppBarLayout)。