Den*_*ero 3 android android-fragments android-recyclerview
问题
在我的Activity初始化a 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>
Run Code Online (Sandbox Code Playgroud)
这里是片段中的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>
Run Code Online (Sandbox Code Playgroud)
解决方法
我已经尝试的话match_parent中RecyclerView,也增加了paddingBottom它.使用paddingBottom ="30dp"可以看到更多元素,但这不是一个好的解决方案.此外,我Activity正在使用 - AlertDialog中设置的主题Manifest.删除它显示相同的结果.
任何帮助将不胜感激.
Den*_*ero 14
我终于修好了.问题出wrap_content在我的RecyclerView内心ConstraintLayout.通过使用父母wrap_content的高度RecyclerView切断它的底部.所以你必须使用0dp作为高度和一个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"/>
Run Code Online (Sandbox Code Playgroud)