简体   繁体   English

CollapsingToolbarLayout折叠时显示标题损坏

[英]CollapsingToolbarLayout showing broken title when collapsed

Bugged title 标题错误

Hey, as you can see in this picture, I am trying to use the CollpasingToolbarLayout but the title is not being drawn correctly. 嘿,正如您在这张照片中看到的,我正在尝试使用CollpasingToolbarLayout,但是标题绘制不正确。 In the expanded state I set the title to fade out like this: 在展开状态下,我将标题设置为淡入淡出,如下所示:

val collapsingToolbarLayout = layout.findViewById<CollapsingToolbarLayout>(R.id.collapsing_toolbar)
    collapsingToolbarLayout.setExpandedTitleColor(android.R.color.transparent)

so the expanded state isn't really important. 因此扩展状态并不是很重要。 My xml looks like this: 我的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:fitsSystemWindows="true">

    <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:fitsSystemWindows="true"
        app:expanded="false"
        >

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

            <CalendarView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="35dp"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                app:title="Title"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin">

            </android.support.v7.widget.Toolbar>

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

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

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <include layout="@layout/main_fragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

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

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

Whan can I try? 我可以尝试吗? I am thinking this is a bug but I wouldn't know. 我认为这是一个错误,但我不知道。 Thanks 谢谢

android:fitsSystemWindows="true" typically adds the appropriate padding in some cases to make sure that views are not layered under the status bar/nav bar. android:fitsSystemWindows="true"通常会在某些情况下添加适当的填充,以确保视图未在状态栏/导航栏下分层。 In your case, I think that is the cause of pushing your text downwards. 就您而言,我认为这是将您的文字向下推的原因。

You may need to play around with this, but try removing it for your AppBarLayout and its children and perhaps try some different combinations. 您可能需要尝试一下,但是请尝试将其删除以用于您的AppBarLayout及其子级,并尝试一些不同的组合。

It may also help to show us the view boundaries so we can see where the views actually are. 这也可能有助于向我们显示视图边界,以便我们可以查看视图的实际位置。 This can be done either in the Android Studio preview or via developer options 这可以在Android Studio预览中或通过开发人员选项来完成

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM