工具栏中的自定义布局,下面是 TabLayout [英] Custom layout in Toolbar with TabLayout below

查看:24
本文介绍了工具栏中的自定义布局,下面是 TabLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我有一个普通的工具栏.我想要做的是在ToolbarTabLayout之间添加一个自定义布局,如下图所示:

Right now, I have a normal looking Toolbar. What I want to do is add a custom layout between the Toolbar and the TabLayout, as shown in the picture below:

左边是我的 Toolbar 现在的样子,右边是我想要的样子.

On the left is what my Toolbar looks like now, and on the right is what I want it to look like.

如您所见,我想在布局中添加一个 ImageView 和两个 TextView.

As you can see, I want to add an ImageView and two TextViews to the layout.

我怎样才能做到这一点?

How can I achieve this?

这是我当前的布局:

<?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"
    android:id="@+id/main_content"
    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="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tablayout"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            app:layout_scrollFlags="scroll|enterAlways" />

    </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 扩展了 LinearLayout,因此您可以向 AppBarLayout 添加任意数量的视图:没有理由将视图专门添加到您的 工具栏.

AppBarLayout extends LinearLayout, so you can add any number of views to your AppBarLayout: there's no reason to add the views specifically to your Toolbar.

如果您希望它们滚动相同,请确保使用与 Toolbar 相同的 layout_scrollFlags.

You'll want to make sure you use the same layout_scrollFlags as your Toolbar if you want them to scroll the same.

这篇关于工具栏中的自定义布局,下面是 TabLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆