所以,在我的项目中,我的CollapsingToolbarLayout遇到了一个wierd问题。在我的活动开始后,我的工具栏标题就是这样显示的:
android - 扩展的CollapsingToolbarLayout中的标题未正确显示-LMLPHP
折叠布局后如下所示:
android - 扩展的CollapsingToolbarLayout中的标题未正确显示-LMLPHP
示例中的原始标题文本是:“upc vonalkodos termek”
我认为扩展状态下的标题应该比崩溃状态下的标题更长(有足够的空间)。我的活动的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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    app:theme="@style/PolarThemeNoActionBar">
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_below="@+id/tablayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        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="142dp"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginBottom="20dp"
            app:expandedTitleTextAppearance="@style/ExpandedText">
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                android:minHeight="?attr/actionBarSize"
                app:layout_collapseMode="pin"/>
            </android.support.design.widget.CollapsingToolbarLayout>
        <android.support.design.widget.TabLayout
            android:id="@+id/tablayout"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_below="@+id/toolbar"
            android:minHeight="?attr/actionBarSize"
            android:gravity="bottom"
            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:tabIndicatorColor="?attr/colorPrimaryDark"/>
        </android.support.design.widget.AppBarLayout>
    </android.support.design.widget.CoordinatorLayout>

我的res/style/expandedText看起来像:
<style name="ExpandedText" parent="android:TextAppearance">
    <item name="android:textColor">@android:color/white</item>
    <item name="android:textSize">20sp</item>
    </style>

支持库版本:25.1.1。
电话:Nexus 5
Android版本:6.0.1(库存)
我的问题是:为什么标题的末尾有点处于展开状态,而没有填满显示更多内容的空间?
[编辑1]支持库版本25.3.0仍存在问题

最佳答案

CollapsingToolbarLayout使用一个helper类来绘制其标题并设置其动画。在编写本文时,该类的最新版本将扩展标题的可用宽度限制为基于折叠状态下可用宽度的大小,并按状态文本大小的比例缩放。
相关来源评论:

// If the scaled down size is larger than the actual collapsed width, we need to
// cap the available width so that when the expanded text scales down, it matches
// the collapsed width

这显然是为了解决一些边缘情况,如the relevant commit注释中所述,标题会与其他CollapsingTextHelper内容重叠。
修复在图标上显示折叠工具栏布局
CTL缩放它的标题,这在大多数情况下都有效。
虽然标题可以是
绘制在工具栏上的内容,即图标。
这个cl修复了折叠的
扩展文本的大小与
意味着没有发生缩放
滚动时。在这种情况下,我们需要
展开时的任何可用宽度,以便
“缩放”以匹配折叠时的折叠宽度。
通常情况下,我都会将类分解成Toolbar类,用反射和其他技巧来修改它们的行为,但是在这种情况下,给定的设置会使这需要一些非常繁重的工作。helper类通常在库包外不可访问,它的实例在View中是私有的,并且大小计算是在一个私有的、次要的方法中执行的,其中大部分是本地变量。
如果有可能的话,最简单的解决方案是恢复到在此修复之前发布的库版本。我还没有确定带来这一变化的确切版本,support library revision history似乎没有提到,不幸的是。不过,这一承诺是在去年(2016年)年中做出的,所以可能是在24.0.0左右,或者稍晚。我可以验证23.4.0中不存在该行为。
如果你愿意的话,你当然可以file a bug report,尽管不能保证他们会认为这是一个bug。我没有发现任何以前提出的关于这一点的具体问题,除了抱怨省略是这一变化的副作用。

07-24 09:46
查看更多