2017-09-01 12 views
1

Das ProblemRecyclerView zeigt nicht alle Elemente innerhalb Fragment

In meinem Activity initialisieren ich ein Fragment, die eine RecyclerView enthält. Aber ich habe erkannt, dass es nicht alle Artikel anzeigt. Das bedeutet, dass anstelle von 14 nur 11 Elemente angezeigt werden. Darüber hinaus wird die letzte sichtbare Element (Nummer 12) abgesägt

Meine Implementierung

Die Activity eine leere FrameLayout enthält, die als Fragment Behälter wirkt:

<?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> 

Und hier ist die RecyclerView in dem Fragment:

<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> 

Lösungsansätze

ich schon versucht, es mit match_parent im RecyclerView und auch eine paddingBottom ihm hinzugefügt. Mit paddingBottom = "30dp" ist ein weiteres Element sichtbar, aber das ist keine gute Lösung. Desweiteren verwendet mein Activity das AlertDialog -Thema, das in Manifest eingestellt ist. Das Entfernen zeigt das gleiche Ergebnis.

Jede Hilfe würde sehr geschätzt werden.

+1

ändern 'android: layout_above = "@ id/layout_footer"' auf 'android: layout_above = "@ + id/layout_footer"' Auch warum verwenden Sie 'App: layout_constraintTop_toBottomOf = "@ + id/layout_header" 'für' RecyclerView' – Piyush

+0

Danke für den Hinweis, aber das hat nicht geholfen. Ich verwende 'app: layout_constraintTop_toBottomOf =" @ + id/layout_header "' zum Positionieren, da das 'RecyclerView' in einem 'ConstraintLayout' liegt. –

+0

Was ist die übergeordnete Ansicht des RecyclerView? –

Antwort

5

ich es endlich fixiert. Das Problem war die wrap_content in meinem RecyclerView innerhalb ConstraintLayout. Unter Verwendung von wrap_content für die Höhe der RecyclerView schneidet das Elternteil die Unterseite ab. Sie müssen 0dp für die Höhe und einen constraintBottom verwenden.

<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

Ich musste auch von ScrollView zu android.support.v4.widget.NestedScrollView wechseln (wenn Sie ein Scroll-Layout verwenden). – Yani2000

2

bereites xml folgenden als Einschränkung Bauräume ändern hüllt, wenn sie in eine falsche Art und Weise verwendet:

<?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

Vielen Dank! Ich löste es mit meinem 'ConstraintLayout' –

Verwandte Themen