【问题标题】:Why is my ListView begins from the bottom to top?为什么我的 ListView 是从下到上开始的?
【发布时间】:2019-05-27 04:34:51
【问题描述】:

我有一个产品列表视图,这些产品从数据库中一一添加到 ArrayList。 添加的顺序和列表视图是相等的(这样就可以了)。

我的问题是产品是从页面中间显示的 (我必须向下滚动很多才能看到它们)。 listview display 我的 XML :

<ListView
    android:id="@+id/listviewmanager"
    android:layout_width="fill_parent"
    android:layout_height="457dp"
    android:layout_alignParentLeft="true"
    android:clickable="false"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintVertical_bias="1.0" >

    <ScrollView
        android:id="@+id/scrollView2"
        android:layout_width="match_parent"
        android:layout_height="474dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" />
    </ScrollView>
</ListView>

谢谢。

【问题讨论】:

  • 为什么你的列表视图中有滚动视图和线性布局?
  • 因为滚动有问题,所以我添加了这个。你有更好的选择吗?我想听听:)
  • 请分享您的整个 XML 代码。我也相信前两项是空的,因为您可以在屏幕截图上看到分隔线,但没有数据。

标签: android xml android-studio listview


【解决方案1】:

在您的ListView 中替换此行

android:layout_height="457dp"

用这条线

android:layout_height="match_parent"

使用match_parent,您不仅可以使用ListView 填充整个屏幕457dp

【讨论】:

  • @D123 从列表视图中删除滚动视图和线性布局。 (并将高度设置在 match_parent 上)
猜你喜欢
  • 2017-12-11
  • 1970-01-01
  • 1970-01-01
  • 2016-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-22
相关资源
最近更新 更多