CollapsingToolbarLayout不工作(崩溃),滚动时 [英] CollapsingToolbarLayout not working(collapsing)when scrolled

本文介绍了CollapsingToolbarLayout不工作(崩溃),滚动时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个 Col​​lapsingToolbarLayout 和它下面列表视图,当列表视图滚动工具栏应该崩溃,但它不工作滚动时,工具栏不会崩溃

I am trying to create a CollapsingToolbarLayout and below it a listview, when the listview is scrolled the Toolbar should collapse, but its not working when scrolled the Toolbar is not collapsing.

用于本教程: http://android-developers.blogspot.in/2015_05_01_archive.html

注:的FrameLayout包含列表视图

Note: The FrameLayout contains the listview

    <LinearLayout 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:orientation="vertical"
        android:scrollbars="vertical">

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

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbara"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="?attr/colorPrimary"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
            </android.support.design.widget.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>

        <FrameLayout
            android:id="@+id/frame"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>

本的FrameLayout code:

The framelayout code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="ranjithnair02.com.supporttest.BlankFragment">

    <ListView
        android:id="@+id/rcyv"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="10dp"
        android:layout_marginRight="10dp"
        android:src="@android:drawable/ic_search_category_default"
        app:borderWidth="0dp"
        app:elevation="5dp"
        app:rippleColor="@color/wallet_highlighted_text_holo_light" />
</RelativeLayout>

推荐答案

您应该使用<一个href="http://developer.android.com/reference/android/support/v7/widget/RecyclerView.html">RecyclerView而不是ListView控件

You should use RecyclerView instead of ListView

请注意: 不要忘了在摇篮文件更新RecyclerView。

Note: don't forget to update RecyclerView in Gradle file.

  compile 'com.android.support:recyclerview-v7:22.2.0'

这篇关于CollapsingToolbarLayout不工作(崩溃),滚动时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆