CollapsingToolbarLayout信息涵盖标题

时间:2015-07-10 16:41:13

标签: android android-collapsingtoolbarlayout

有人知道在使用CollapsingToolbarLayout时如何在标题下添加信息吗?

我使用mCollapsingToolbarLayout.setTitle(myTitle)设置标题,您可以在屏幕截图中看到它。在布局中,我还设置了一些其他的东西(评级和类别)。正如您所看到的,标题背后是额外的信息。有人知道一个很好的方法来解决这个问题吗?谢谢!

截屏: enter image description here

这是我的布局文件:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/background">
<!-- The main content view -->

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/coordinator_layout"
    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="0dp"
        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"
            app:collapsedTitleTextAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/iv_detailHeaderImage"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="1.0" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:background="?attr/colorPrimary"
                android:gravity="bottom"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/tv_detailCategory"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingEnd="@dimen/activity_horizontal_margin"
                    android:paddingLeft="@dimen/activity_horizontal_margin"
                    android:paddingRight="@dimen/activity_horizontal_margin"
                    android:paddingStart="@dimen/activity_horizontal_margin"
                    android:text="category"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/abc_text_size_small_material"
                    android:textStyle="bold" />


                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@android:color/transparent"
                    android:gravity="start|center_vertical"
                    android:orientation="horizontal"
                    android:paddingEnd="@dimen/activity_horizontal_margin"
                    android:paddingLeft="@dimen/activity_horizontal_margin"
                    android:paddingRight="@dimen/activity_horizontal_margin"
                    android:paddingStart="@dimen/activity_horizontal_margin">

                    <TextView
                        android:id="@+id/tv_detailRatingNumber"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textColor="@android:color/white"
                        android:textSize="@dimen/abc_text_size_small_material" />

                    <RatingBar
                        android:id="@+id/rb_detailRatingBarStars"
                        style="?android:attr/ratingBarStyleIndicator"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:numStars="5"
                        android:progressDrawable="@drawable/rating_star_white"
                        android:stepSize="0.1" />

                    <TextView
                        android:id="@+id/tv_detailRatingAmount"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textColor="@android:color/white"
                        android:textSize="@dimen/abc_text_size_small_material" />

                    <TextView
                        android:id="@+id/tv_detailRatingBarDollars"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textColor="@android:color/white"
                        android:textSize="@dimen/abc_text_size_small_material" />

                </LinearLayout>
            </LinearLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?actionBarSize"
                android:gravity="bottom"
                android:paddingEnd="0dp"
                android:paddingLeft="8dp"
                android:paddingRight="0dp"
                android:paddingStart="8dp"
                app:layout_collapseMode="pin" />
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

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

        <include
            android:id="@+id/ll_detailParent"
            layout="@layout/venue_detail_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </android.support.v4.widget.NestedScrollView>

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

<!-- The drawer content view -->
<android.support.design.widget.NavigationView
    android:id="@+id/nv_nav_drawer_main"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/drawer_list_header"
    app:menu="@menu/drawer_items" />

1 个答案:

答案 0 :(得分:2)

我遇到了类似的问题,并在此处发布了我用来修复它的代码:

https://stackoverflow.com/a/31529101/834692

希望你也可能觉得这很有用。祝你好运!