CollapsingToolbarLayout无效..无法显示应用名称

时间:2016-08-20 13:13:51

标签: android android-layout android-coordinatorlayout android-appbarlayout

这里基本上我试图让我在向上滚动数据时工具栏崩溃的CoordinatorLayout行为。但是,工具栏已完全冻结且未折叠。此外,我试图在工具栏上显示未显示的数据,如下所示。

enter image description here enter image description here

<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:orientation="vertical"
    android:background="@android:color/background_light"
    android:fitsSystemWindows="true"
    >

    <android.support.design.widget.AppBarLayout
        android:id="@+id/main.appbar"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:fitsSystemWindows="true"
        >

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

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/logo"
            android:contentDescription="@string/app_name"
            android:scaleType="centerCrop"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax"
            />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            android:layout_marginLeft="@dimen/list_toolbar_side_margin"
            android:layout_marginRight="@dimen/list_toolbar_side_margin"
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"
            android:layout_gravity="bottom"
            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.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            android:scrollbarStyle="outsideOverlay"
            android:paddingTop="116dp"
            android:paddingLeft="@dimen/list_side_margin"
            android:paddingRight="@dimen/list_side_margin"
            android:paddingBottom="28dp" />
    </android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>

1 个答案:

答案 0 :(得分:0)

首先,您需要在swiperefreshlayout中使用此行。

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

对于显示名称,请检查您的AndroidMenifest文件。您可能错过了添加标签属性

<activity
        android:name=".MainActivity"
        android:label="Main Activity"
        android:screenOrientation="portrait"/>