【问题标题】:Title in CollapsingToolbarLayout truncates on SearchView openCollapsingToolbarLayout 中的标题在 SearchView 打开时被截断
【发布时间】:2020-11-22 23:11:51
【问题描述】:

每当我在CollapsingToolbarLayout 中打开SearchView 时,页面标题会由于某种原因被压扁并截断到一侧,而不是位于SearchView 小部件下方。有没有办法防止这种情况发生?

主布局

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/myCoordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include layout="@layout/collapsing_toolbar" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/myRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical"
        android:scrollbarStyle="outsideInset"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/myFab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:src="@drawable/ic_search"
        android:contentDescription="@string/string_search"
        android:layout_margin="16dp" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

折叠工具栏布局

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.appbar.AppBarLayout
    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="wrap_content"
    android:id="@+id/myAppBarLayout">

    <com.google.android.material.appbar.CollapsingToolbarLayout
        android:id="@+id/myCollapsingToolbarLayout"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:fitsSystemWindows="true"
        app:layout_scrollFlags="scroll|snap|exitUntilCollapsed"
        app:maxLines="3">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/myToolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:contentInsetStartWithNavigation="0dp"
            app:layout_collapseMode="pin" />
    </com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>

【问题讨论】:

    标签: android kotlin android-toolbar android-search


    【解决方案1】:

    您的 CollapsingToolbarLayout 已被您的 RecyclerView 覆盖,请尝试更改 主布局

    【讨论】:

      猜你喜欢
      • 2012-04-16
      • 2011-09-07
      • 1970-01-01
      • 1970-01-01
      • 2015-09-24
      • 1970-01-01
      • 2013-08-20
      • 2016-07-28
      • 2021-11-17
      相关资源
      最近更新 更多