【问题标题】:Listview inside constraintLayout not scrolling约束布局内的Listview不滚动
【发布时间】:2018-12-21 08:01:06
【问题描述】:

我的 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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <TextView
        android:id="@+id/special_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@android:color/white"
        android:layout_marginLeft="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="Today is:"
        android:textSize="24sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:visibility="gone"
        app:layout_constraintTop_toTopOf="parent"/>

    <TextView
        android:id="@+id/date_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@android:color/white"
        android:layout_marginLeft="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="The date is:"
        android:textSize="24sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/special_text_view"/>



     <TextView
            android:id="@+id/oc_text_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@android:color/white"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:text="The day of the omer is:"
            android:visibility="gone"
            android:textSize="24sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/date_text_view"/>

    <ListView
    android:id="@+id/zmanim_list_view"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_marginTop="24dp"
    android:layout_marginBottom="24dp"
    app:layout_constraintTop_toBottomOf="@id/omer_chanukah_text_view"
    app:layout_constraintBottom_toBottomOf="parent">

</ListView>

    </android.support.constraint.ConstraintLayout>

谢谢

【问题讨论】:

  • 试着给listview宽度0dp和listview开始和结束约束。

标签: android listview android-constraintlayout


【解决方案1】:

我的 ListView 没有在 ConstraintLayout 内滚动时遇到了同样的问题。对我来说,解决方案是将 ListView 设置为 android:layout_height="0dp" 并带有顶部和底部约束。

示例

<ListView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_constraintTop_toBottomOf="@id/textview_above_this_one"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    >
</ListView>

【讨论】:

    【解决方案2】:

    您是否包含了整个布局?在您实际包含的内容中,您的 TextView 具有以下属性:

    app:layout_constraintTop_toBottomOf="parent"
    

    当我使用此布局运行应用程序时,这会导致屏幕上不显示任何视图。如果我将其更改为

    app:layout_constraintTop_toTopOf="parent"
    

    然后我看到一切正常(ListView 没有被剪裁)。

    【讨论】:

    • 嗨,我排除了中间的几个文本视图,你指出的是一个错误,我修复了它,但它仍然不适合我。
    • @Jack 您排除的视图可能是问题的一部分。
    • 不这么认为,只是添加了其余的以防万一。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-10
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 1970-01-01
    • 2019-01-05
    • 1970-01-01
    相关资源
    最近更新 更多