CollapsingToolbarLayout字幕 [英] CollapsingToolbarLayout subtitle

查看:194
本文介绍了CollapsingToolbarLayout字幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够设置CollapsingToolbarLayout通过的<一个标题href="https://developer.android.com/reference/android/support/design/widget/CollapsingToolbarLayout.html#setTitle(java.lang.CharSequence)">setTitle法。有没有一种办法还设置了字幕? 谢谢

I'm able to set the title of a CollapsingToolbarLayout via the setTitle method. Is there a way to set also a subtitle? Thanks

推荐答案

如果您想让小标题去工具栏 AppBar 已完全坍塌,你应该创建自定义 CoordinatorLayout.Behaviour 这样的: Github的指南

If you want the subtitle to go to Toolbar when the AppBar is fully collapsed you should create your custom CoordinatorLayout.Behaviour Like this: Github Guide

但如果你只是想在标题较小的文本时, AppBar 扩展你可以试试这个布局:

But if you just want a smaller text behind the title when the AppBar is expanded you can try this layout:

<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:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
        <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:expandedTitleMarginBottom="160dp"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">
            <ImageView
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/quila2"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax" />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="@dimen/abc_text_size_subhead_material"
                android:textColor="@android:color/white"
                android:layout_marginBottom="32dp"
                android:layout_marginEnd="64dp"
                android:layout_marginStart="48dp"
                app:layout_collapseMode="parallax"
                android:layout_gravity="bottom"
                android:text="Lorem Ipsum Iran Lorem Ipsum Iran Lorem Ipsum Iran Lorem Ipsum Iran Lorem Ipsum Iran Lorem Ipsum Iran Lorem Ipsum Iran Lorem Ipsum Iran "/>
            <android.support.v7.widget.Toolbar
                android:id="@+id/anim_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="16dp"
            android:lineSpacingExtra="8dp"
            android:text="@string/lorem"
            android:textSize="18sp"/>

    </android.support.v4.widget.NestedScrollView>

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:clickable="true"
        android:src="@drawable/abc_ic_search_api_mtrl_alpha"
        app:layout_anchor="@+id/appbar"
        app:layout_anchorGravity="bottom|right|end" />

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

请注意,这里我设置了 AppBar 高度 300dp 应用程序:expandedTitleMarginBottom 160dp 这样的标题不会下降,并与出字幕的冲突。 方法;在这个例子中,你应该与运行collapsingToolbarTitle.setTitle(我的标题)中设置 Col​​lapsingToolbarTitle 动态。

Notice that here I set the AppBar height as 300dp and the app:expandedTitleMarginBottom is 160dp so the title won't go down and conflict with the out subtitle. In this example you should set CollapsingToolbarTitle dynamically in the runtime with collapsingToolbarTitle.setTitle("My Title"); method.

其结果将是这样的:

输入图像的描述在这里

这篇关于CollapsingToolbarLayout字幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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