CollapsingToolbarLayout扩展无法与RecyclerView一起使用

时间:2015-06-12 21:34:24

标签: android android-support-library material-design android-design-library android-collapsingtoolbarlayout

CollapsibleToolbarLayout与RecyclerView相关的行为似乎已被破坏。为

设置值时

应用程式:layout_scrollFlags

如果您不使用“scroll | enterAlways”,则Colbsible布局将永远不会展开。它会一直收缩,但当你拉下来时,它不会再扩展,所以它只会被锁定在顶部。

如果您使用“scroll | enterAlways”,它会按预期工作,这意味着每当您向下滚动时,它会立即将标题扩展到其完整高度。

在不知情的情况下,似乎可折叠布局无法正确确定RecyclerView何时位于列表顶部,因为这是在其他情况下应该扩展到完全高度的标准。

这是我正在测试的布局。 java代码并不重要,它只是使用虚拟数据填充recyclerview并使用LinearLayoutManager。

<?xml version="1.0" encoding="utf-8"?>

<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.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:toolbarId="@id/toolbar_id"
        app:contentScrim="@color/white"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

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

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

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

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

2 个答案:

答案 0 :(得分:13)

尝试使用# models.py tiers # compiled invoice with sum of all "cost" in # bill period would be the last step class Service(models.Model): name_of_service = models.CharField(max_length="50") cost = models.CharField(max_length="50") def __unicode__(self): return unicode(self.name_of_service) class Bill_Period(models.Model): start_date = models.DateTimeField(blank=True, null=True) end_date = models.DateTimeField(blank=True, null=True) def __unicode__(self): return unicode(self.start_date) class invoice(models.Model): date_of_service = models.DateTimeField(default=timezone.now(),blank=True) agency_to_bill = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True) patient = models.ForeignKey('users.Patient', blank=True) therapy_completed = models.ForeignKey('Service', blank=True) def __unicode__(self): return unicode(self.agency_to_bill) class compiled_invoice(models.Model): # month, total, paid # views.py i use to handle the information # error message "Relation fields do not support nested lookups" def InvoiceDetail(request, month, year): current_user = request.user invoice_detail = invoice.objects.filter(date_of_service__year=year, date_of_service__month=month, agency_to_bill=current_user) c = invoice.objects.filter(paid=False, date_of_service__year=year, date_of_service__month=month, agency_to_bill=current_user) total = invoice.objects.filter(therapy_completed__Service__cost__isnull=True).aggregate(Sum('cost')) return render_to_response('invoice-detail.html', {'invoice_detail': invoice_detail, 'current_user': current_user, 'month': month, }) 。这样,工具栏应始终以折叠模式进入,然后在到达同级视图顶部时展开。

答案 1 :(得分:-1)

如果要在AppBarLayout下显示带有RecyclerView的列表,则应将RecyclerView XML放在

<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.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    android:fitsSystemWindows="true">

<android.support.design.widget.CollapsingToolbarLayout
    android:id="@+id/collapsing_toolbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    app:toolbarId="@id/toolbar_id"
    app:contentScrim="@color/white"
    app:layout_scrollFlags="scroll|exitUntilCollapsed">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar_id"
        android:layout_width="match_parent"
        android:layout_height="?android: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/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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