Ich habe ein Fragment mit einer Symbolleiste und einer recyclerView darin.
Ich fülle die recyclerView mit Dummy-Daten und versuche dann, sie anzuzeigen. Aus irgendeinem Grund wird das letzte Element von recyclerView abgeschnitten.
Dies ist das XML des Fragments:
<?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:background="@color/background_1"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="@dimen/height_of_app_bar"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="@color/primary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="https://stackoverflow.com/questions/32742724/@drawable/placeholder_rect_header"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/simpleList"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
Die Punkte auf der Liste sind wirklich einfach:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@color/background_1"
android:orientation="horizontal"
android:padding="@dimen/space_for_a_bit_of_air">
<ImageView
android:id="@+id/album_cover"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_vertical"
android:scaleType="fitXY"
android:src="https://stackoverflow.com/questions/32742724/@drawable/placeholder_album_cover"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/space_for_distinguishing_stuff"
android:orientation="vertical">
<TextView
android:id="@+id/album_title"
style="@style/titleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sample_text_c"/>
<TextView
android:id="@+id/album_year"
style="@style/subtitleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sample_text_a"/>
</LinearLayout>
</LinearLayout>
Ich bin jetzt am Ende der Liste, aber das letzte Element sieht immer noch abgeschnitten aus.
Ich verwende die neueste Version vom 23.09.2015 der Google-Bibliotheken, 23.0.1, (dh com.android.support:recyclerview-v7:23.0.1) und die folgende Konfiguration bei build.gradle:
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true// Enabling multidex support
}
Jede Hilfe wäre sehr dankbar, da ich mit diesem Problem verrückt werde 🙁
LÖSUNG
Ok, nachdem ich den Code auf das Nötigste gesäubert und die Komplexität entfernt hatte, fand ich das Problem: Es war eine Kombination aus falschen Flags und fehlenden oder zusätzlichen Attributen. Folgendes funktioniert sowohl für Android 4.x als auch für 5.x einwandfrei:
<?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:background="@color/background_1"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="@dimen/height_of_app_bar"
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:collapsedTitleTextAppearance="@style/Title.collapsed"
app:contentScrim="@color/primary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleTextAppearance="@style/Title.Expanded"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed">
<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="https://stackoverflow.com/questions/32742724/@drawable/artistic_4"
app:layout_collapseMode="parallax"/>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/height_of_app_bar"
android:background="@drawable/gradient"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/simpleList"
style="@style/genericRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:listitem="@layout/item_discography_album"/>
</android.support.design.widget.CoordinatorLayout>
Kurz gesagt, android:fitsSystemWindows=”true” sollte nur bei coordinatorLayout, AppBarLayout und theCollapsingToolbarLayout (die wir basierend auf dem Bildschirm auf Android 5.x anpassen möchten) stehen, die app:layout_scrollFlags sollten gesetzt sein auf “scroll|enterAlways|enterAlwaysCollapsed” und die Symbolleiste sollte als Höhe die Höhe der actionBar haben. Schließlich ist es besser, die RecyclerView so sauber wie möglich zu halten, damit Sie den Layoutabstand bei jedem Zeilenelement steuern können.
Meins ist ein einfaches Constraint-Layout mit nur einer Symbolleiste und einer Recycleransicht. Ihre Lösung passt möglicherweise nicht in meinen Fall. Aber die @Rami-Lösung klingt für das gemeldete Problem generisch, da die Höhe des Appbar-Layouts als unterer Rand angepasst werden musste, um das Problem zu beheben.
– PravyNandas
12. Oktober 2018 um 10:56 Uhr