RecyclerView不显示内部片段

问题描述:

问题RecyclerView不显示内部片段

在我Activity我初始化Fragment,其中包含了RecyclerView的所有项目。但我意识到它没有显示所有项目。这意味着,而不是14它只显示11项。除了最后一个可见项目(编号12)板缺掉

我实现

Activity包含空FrameLayout充当Fragment容器:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res./android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="#e0e0e0"> 

<LinearLayout 
    android:id="@+id/layout_footer" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:background="@drawable/layout_border_white" 
    android:paddingBottom="@dimen/footer_padding"> 

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

</LinearLayout> 


<FrameLayout 
    android:id="@+id/fragment_start" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@id/layout_footer"/> 

</RelativeLayout> 

这里是RecyclerView在片段中:

<android.support.constraint.ConstraintLayout 
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:background="#e0e0e0" 
android:orientation="vertical"> 

<LinearLayout 
    android:id="@+id/layout_header" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:background="@android:color/white" 
    android:padding="@dimen/startpage_padding" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent"> 

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

</LinearLayout> 


<android.support.v7.widget.RecyclerView 
    android:id="@+id/recycler_view" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_margin="@dimen/startpage_margin" 
    android:scrollbars="vertical" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toBottomOf="@+id/layout_header"/> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent"> 

    <ProgressBar 
     android:id="@+id/pb_loading_indicator" 
     android:layout_width="@dimen/startpage_progressbar" 
     android:layout_height="@dimen/startpage_progressbar" 
     android:visibility="invisible"/> 

</LinearLayout> 


<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent"> 

    <TextView 
     android:id="@+id/tv_error_message_display" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:padding="@dimen/startpage_text_padding" 
     android:text="@string/error_message" 
     android:textSize="@dimen/startpage_text" 
     android:visibility="invisible"/> 
</LinearLayout> 

解决途径

我已经与match_parent试过在RecyclerView,并还增加了一个paddingBottom它。用paddingBottom =“30dp”可以看到更多的元素,但这不是一个好的解决方案。此外,我的Activity正在使用AlertDialog-设置在Manifest中的主题。删除它显示相同的结果。

任何帮助将不胜感激。

+1

变化'机器人:layout_above = “@ ID/layout_footer”'到'机器人:layout_above = “@ + ID/layout_footer”'还有为什么你使用'应用:layout_constraintTop_toBottomOf = “@ + ID/layout_header” 'RecyclerView' – Piyush

+0

感谢提示,但没有帮助。我使用'app:layout_constraintTop_toBottomOf =“@ + id/layout_header”'进行定位,因为'RecyclerView'位于'ConstraintLayout'中。 –

+0

RecyclerView的父视图是什么? –

我终于固定它。问题是我的RecyclerView中的wrap_contentConstraintLayout。通过使用wrap_content作为RecyclerView的高度,父母将其底部切掉。所以你必须使用0dp作为height和一个constraintBottom。

<android.support.v7.widget.RecyclerView 
    android:id="@+id/recycler_view" 
    android:layout_width="0dp" 
    android:layout_height="0dp" 
    android:layout_margin="@dimen/startpage_margin" 
    android:scrollbars="vertical" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintTop_toBottomOf="@+id/layout_header"/> 
+0

我也必须从ScrollView更改为android.support.v4.widget.NestedScrollView(如果使用滚动布局)。 – Yani2000

尝试你的XML更改为以下方面的约束布局包装空间不正确的方式使用时:

<?xml version="1.0" encoding="utf-8"?> 
<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="match_parent" 
    android:orientation="vertical" 
    android:background="#e0e0e0"> 

    <LinearLayout 
     android:id="@+id/layout_header" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@android:color/white"> 

     <include layout="@layout/support_simple_spinner_dropdown_item"/> 
    </LinearLayout> 


    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recycler_view" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="@dimen/startpage_margin" 
     android:scrollbars="vertical" 
     android:layout_below="+id/layout_header" 
     /> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent"> 

     <ProgressBar 
      android:id="@+id/pb_loading_indicator" 
      android:layout_width="match_parent" 
      android:layout_height="10dp" 
      android:layout_centerInParent="true" 
      android:visibility="invisible"/> 

     <TextView 
      android:id="@+id/tv_error_message_display" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:gravity="center" 
      android:text="Error" 
      android:textSize="20sp" 
      android:visibility="invisible"/> 

    </RelativeLayout> 
</LinearLayout> 
+0

谢谢!我用我的'ConstraintLayout'解决了它 –