ListView只显示6个项目



各位外国朋友好!

我试图列出JSON调用的返回,然而,当在Android ListView中查看项目时,只显示6个项目(最后一个,减半)。

  • 我检查了API调用,大约有20项返回;
  • 验证了改装对象,它包含一个包含20个对象的数组;

在我的pov中,问题是在布局中,由于某种原因没有渲染所有对象。

下面是xml:
<androidx.coordinatorlayout.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_height="match_parent"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:background="#050505">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayoutView"
android:layout_width="match_parent"
android:layout_height="420dp"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapseToolBarLayoutView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="@android:color/secondary_text_light"
app:expandedTitleMarginBottom="20dp"
app:expandedTitleMarginStart="15dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<ImageView
android:id="@+id/singlePostPathView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_transp" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical">
<TextView
android:id="@+id/singleTitleView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textColor="#FFFFFF"
android:text="Top 10 Morgan Freeman Movies"
android:textStyle="bold"
android:textSize="38dp"
android:maxLines="2"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="@+id/likeButtonVIew"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="@+id/userLikesIconView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginStart="10dp"
android:layout_marginBottom="15dp"
android:src="@drawable/ic_like"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/singleTitleView" />
<ImageView
android:id="@+id/likeButtonVIew"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginTop="10dp"
android:src="@drawable/ic_like_btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/userRateView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="719 Curtidas"
android:layout_marginStart="5dp"
android:textColor="#FFFFFF"
android:textSize="16sp"
app:layout_constraintStart_toEndOf="@+id/userLikesIconView"
app:layout_constraintTop_toTopOf="@+id/userLikesIconView"
app:layout_constraintBottom_toBottomOf="@+id/userLikesIconView"/>
<ImageView
android:id="@+id/watchesIconVIew"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:src="@drawable/ic_rd"
app:layout_constraintTop_toTopOf="@+id/userLikesIconView"
app:layout_constraintBottom_toBottomOf="@+id/userLikesIconView"
app:layout_constraintStart_toEndOf="@+id/userRateView"/>
<TextView
android:id="@+id/watchesVIew"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/singleTitleView"
android:layout_marginStart="5dp"
android:text="0 de 10 Assistidos"
android:textColor="#FFFFFF"
android:textSize="16sp"
app:layout_constraintStart_toEndOf="@+id/watchesIconVIew"
app:layout_constraintBottom_toBottomOf="@+id/userLikesIconView"
app:layout_constraintTop_toTopOf="@+id/userLikesIconView"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_below="@+id/appBarLayoutView"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<ListView
android:id="@+id/similar_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="@layout/items_similar" />
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

为了实现目标,是否需要设置任何属性?

首先不怪你,但你的layout应该以更高级的方式设置。在性能和逻辑方面还可以做得更多。检查你的rootView是一个CoordinatorLayout和一个NestedScrollView组合在整个屏幕内滚动。

Be aware,NEVER使用ScrollViewListViewRecyclerView-再次-NEVER

!我的参考:Android Developer

看到任何我需要添加一个CoordinatorLayout。我希望你的rootView不是AppBarLayout.

另一点,使ListView可滚动。如果不是这样,那就解释一下为什么ListItems在6个项目之后被砍掉了。这也是由Layout引起的,ListView没有机会滚动。默认情况下,它应该是可滚动的。

最后但并非最不重要的是,检查您的列表是否有限或看起来像这样:

@Override
public int getCount() {
return yourArrayList.length;
}

最新更新