我有一个RecyclerView
,它没有显示最后一个项目,我知道有很多类似的帖子,但是整天我都在试图对文件进行更改而没有成功,我想主要是原因可能是TabView
,因为没有它,它的作用就像是一种魅力。 RecyclerView由以下include调用。.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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/cardViewBackground">
<android.support.design.widget.TabLayout
android:id="@+id/address_filter_tl"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_gravity="start"
android:background="@color/colorPrimary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tabGravity="fill"
app:tabIndicatorColor="@color/primaryWhite"
app:tabMode="fixed"
app:tabSelectedTextColor="@color/primaryWhite"
app:tabTextColor="@color/inactiveTabText"
android:layout_marginBottom="?attr/actionBarSize">
<android.support.design.widget.TabItem
android:id="@+id/search_results_tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/search_result" />
<android.support.design.widget.TabItem
android:id="@+id/address_book_tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/address_book" />
</android.support.design.widget.TabLayout>
<android.support.v7.widget.CardView
android:id="@+id/my_location_cv"
android:layout_width="0dp"
android:layout_height="72dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:clickable="true"
android:focusable="true"
app:cardElevation="2dp"
app:layout_constraintBottom_toTopOf="@id/search_results_cv"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/address_filter_tl">
<android.support.constraint.ConstraintLayout
android:id="@+id/my_location_cl"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_margin="16dp"
app:layout_constraintBottom_toBottomOf="@id/my_location_cl"
app:layout_constraintStart_toStartOf="@id/my_location_cl"
app:layout_constraintTop_toTopOf="@id/my_location_cl"
app:srcCompat="@drawable/ic_my_location"
tools:ignore="ContentDescription" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="72dp"
android:text="@string/my_location"
android:textColor="@color/primaryBlack"
android:textSize="16sp"
app:layout_constraintBottom_toTopOf="@id/guideline"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/my_location_address_tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="72dp"
android:layout_marginEnd="16dp"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/primaryGreyText"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/guideline"
tools:text="7331 GA Apeldoorn" />
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="36dp" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<include
android:id="@+id/search_results_cv"
layout="@layout/addresses_card_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/my_location_cv" />
<android.support.v7.widget.AppCompatImageView
android:id="@+id/appCompatImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
app:layout_goneMarginBottom="8dp"
android:src="@drawable/powered_by_google"
app:layout_constraintTop_toBottomOf="@id/search_results_cv"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
这是包含内容的布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:clipToPadding="false"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/addresses_rv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingTop="0dp"
android:paddingBottom="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:listitem="@layout/address_item" />
</android.support.constraint.ConstraintLayout>
答案 0 :(得分:1)
如下更改您的include xml,设置layout_height="0dp"
并为其设置底部约束。检查是否有效。
<include
android:id="@+id/search_results_cv"
layout="@layout/addresses_card_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/my_location_cv"
app:layout_constraintBottom_toBottomOf="parent" />