0

我在CoordinaterLayout中使用RecyclerView来显示搜索结果项目。然而,只有滚动一下后才显示这些项目,我无法弄清楚原因。我认为这将与RecyclerView不适应CoordinatorLayout中缩小的尺寸有关。 任何线索?CoordinatorLayout中的RecyclerView仅在滚动后才显示项目

Items showing when scrolling

布局是非常简单明了,并除外RecyclerView由Android工作室提供的基本模板。

activity_results_recycler.xml:

<?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" 
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
    android:layout_height="match_parent" android:fitsSystemWindows="true" 
    tools:context="com.alamgir_swi.abjad.ResultsRecyclerActivity"> 

    <android.support.design.widget.AppBarLayout android:id="@+id/app_bar" 
     android:fitsSystemWindows="true" android:layout_height="@dimen/app_bar_height" 
     android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/toolbar_layout" 
      android:fitsSystemWindows="true" android:layout_width="match_parent" 
      android:layout_height="match_parent" app:layout_scrollFlags="scroll|exitUntilCollapsed" 
      app:contentScrim="?attr/colorPrimary"> 

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

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

    <include layout="@layout/content_results_recycler" /> 

    <android.support.design.widget.FloatingActionButton android:id="@+id/fab" 
     android:layout_width="wrap_content" android:layout_height="wrap_content" 
     android:layout_margin="@dimen/fab_margin" app:layout_anchor="@id/app_bar" 
     app:layout_anchorGravity="bottom|end" android:src="@android:drawable/ic_dialog_email" /> 

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

content_results_recycler.xml:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.RecyclerView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:showIn="@layout/activity_results_recycler" 
    tools:context="com.alamgir_swi.abjad.ResultsRecyclerActivity" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/abjadList" 
    > 
</android.support.v7.widget.RecyclerView> 

abjad_entry.xml:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:padding="10dp" > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="New Text" 
     android:id="@+id/abjad_entry" 
     android:layout_gravity="right" /> 
</RelativeLayout> 

感谢您的任何提示。

+0

在content_results_recycler.xml中使用android:fitsSystemWindows =“true”。看看它是否有效 – Ajay

+0

@Ajay:没有效果 – Aurangzeb

回答

1

发现问题的根源。

我需要从CursorLoader获取数据后,在我的RecyclerView.LayoutManager实例上调用notifyDataSetChanged()。

相关问题