CoordinatorLayout与RecyclerView和放大器; CollapsingToolbarLayout [英] CoordinatorLayout with RecyclerView & CollapsingToolbarLayout

查看:154
本文介绍了CoordinatorLayout与RecyclerView和放大器; CollapsingToolbarLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试实施CollapsingToolbar使用少量的莅临指导一个RecyclerView:<一href="http://android-developers.blogspot.co.uk/2015/05/android-design-support-library.html">http://android-developers.blogspot.co.uk/2015/05/android-design-support-library.html这里的项目: https://github.com/chrisbanes/cheesesquare 和我现在有以下布局:

I've been attempting to implement a CollapsingToolbar with a RecyclerView using the small amount of guidance here: http://android-developers.blogspot.co.uk/2015/05/android-design-support-library.html and the project here: https://github.com/chrisbanes/cheesesquare, and I currently have the following layout:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
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="@dimen/detail_backdrop_height"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true">

    <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"
        android:fitsSystemWindows="true"
        app:theme="@style/Toolbar"
        app:contentScrim="@color/primary"
        app:expandedTitleMarginStart="48dp"
        app:expandedTitleMarginEnd="64dp">

        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax" />

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

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

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

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<android.support.design.widget.FloatingActionButton
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    app:layout_anchor="@id/appbar"
    app:layout_anchorGravity="bottom|right|end"
    android:src="@drawable/ic_directions"
    android:layout_margin="@dimen/fab_margin"
    android:clickable="true"/>

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

源如下:

    setContentView(R.layout.activity_details_image);
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    loadImage();
    CollapsingToolbarLayout collapsingToolbar =
            (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    collapsingToolbar.setTitle(formatName(getIntent().getStringExtra("name")));
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    ArrayList<DetailsAdapter.Detail> details = new ArrayList<DetailsAdapter.Detail>();
    details.add(new DetailsAdapter.Detail("Main Facilities", "Children's Play Area, Ecotricity Electric Vehicle Charging Point, Lucky Coin, Multi Faith Room (southbound only), Showers", R.drawable.ic_moto));
    details.add(new DetailsAdapter.Detail("Restaurants", "Eat & Drink Co., Burger King, Costa, West Cornwall Pasty Co. (northbound only), Greggs, Costa Express, Krispy Kreme", R.drawable.ic_moto));
    details.add(new DetailsAdapter.Detail("Shops", "WHSmith, M&S Simply Food, Fone Bitz, Cotton Traders, Ladbrokes (southbound only)", R.drawable.ic_moto));
    details.add(new DetailsAdapter.Detail("Motel", "Travelodge", R.drawable.ic_moto));
    details.add(new DetailsAdapter.Detail("Forecourt", "BP (with: LPG), Costa Express, Air1 AdBlue", R.drawable.ic_moto));
    DetailsAdapter mAdapter = new DetailsAdapter(this, details);
    recyclerView.setAdapter(mAdapter);
    recyclerView.setItemAnimator(new DefaultItemAnimator());

我测试过它没有倒塌的工具栏,它滚动罚款

I've tested it without the collapsing toolbar and it scrolls fine

然而,它不滚动,即使当该列表的长度比可见部分。我做了什么错?

However it doesn't scroll, even when the list is longer than the visible parts. What have I done wrong?

推荐答案

请确保您使用的 com.android.support:recyclerview-v7:22.2.0

(之前用22.2.0版本,它并没有为我无论工作)

(With version prior to 22.2.0 it didn't work for me either)

这篇关于CoordinatorLayout与RecyclerView和放大器; CollapsingToolbarLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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