折叠式工具栏与选项卡布局

3

我想要实现的目标是:

enter image description here

这个 UI 设计来自 Audio Beats

而这是我现在拥有的:

enter image description here

问题在于,当折叠工具栏展开时,选项卡布局会隐藏在 RecyclerView 后面。而且我无法删除标题“Musico”或将其设置为顶部固定。

我的 XML 代码如下:

<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.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme.AppBarOverlay">

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

        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            android:src="@drawable/hp"
            app:layout_collapseMode="parallax"
            />
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            app:layout_scrollFlags="scroll|enterAlways"
            app:layout_collapseMode="pin"
            android:layout_width="match_parent"
            android:layout_height="90dp"
            app:popupTheme="@style/AppTheme.PopupOverlay" >

        </android.support.v7.widget.Toolbar>
        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            app:tabGravity="center"
            android:layout_gravity="bottom"
            app:tabMode="scrollable" />
    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main"/>
</android.support.design.widget.CoordinatorLayout>

以及 content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_main"
app:behavior_overlapTop="30dp"
>

<android.support.v4.view.ViewPager
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/view_pager"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"></android.support.v4.view.ViewPager>
</RelativeLayout>

请帮忙。

2个回答

0

将TextView(MUsico)移动到工具栏内,并为工具栏提供自定义布局(它将保持在顶部)

布局不正确 请参考:CollaspingLayoutwithviewpager


首先,Musico不是一个TextView。我不知道它是工具栏或折叠式工具栏布局的标题。然而,我没有将标题设置为它们中的任何一个。这是应用程序的名称。其次,我已经访问了链接,它有一个简单的带有折叠式工具栏的选项卡布局。但是我想要像我在第一个gif中展示的自定义视图。 - Brijesh Kumar

-2

只需给选项卡布局添加30dp的底部边距,并在必要时增加应用栏布局的大小。


不起作用。当视图完全折叠时,边距仍然保持不变。 - Brijesh Kumar
我能知道一下,如果您将TabLayout放置在content_main.xml中,并且使用透明背景放置在ViewPager上方,这个问题会被解决吗? - Nivedh
我也尝试过那个,但输出结果与我在第一个gif中提到的不太一样。总的来说,这还不是解决方案。 - Brijesh Kumar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接