Listview不滚动-为什么呢?

时间:2019-03-19 16:43:50

标签: android android-layout listview

我无法使用列表视图滚动。我已经尝试过使用weight = 1focusable = truenestedScrollingEnabled = true进行线性布局(但是我没有nestedscrollview,所以这对我没用)。预先感谢

<com.google.android.material.card.MaterialCardView
    android:id="@+id/materialCardView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="5dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="5dp"
    android:backgroundTint="@android:color/transparent"
    app:cardCornerRadius="10dp"
    app:cardElevation="10dp"
    app:cardPreventCornerOverlap="false"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/topbtns">


    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorAccent">

        <ListView
            android:id="@+id/openedCallsLv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:divider="@null"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/view" />

2 个答案:

答案 0 :(得分:0)

请尝试使用此代码,并让我知道它是否有效

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorAccent">

    <ListView
        android:id="@+id/openedCallsLv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="@null"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/view" />

答案 1 :(得分:0)

尝试将您的列表放在constarintLayout中:

<androidx.constraintlayout.widget.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"


    <com.google.android.material.card.MaterialCardView
        android:id="@+id/materialCardView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:backgroundTint="@android:color/transparent"
        app:cardCornerRadius="10dp"
        app:cardElevation="10dp"
        app:cardPreventCornerOverlap="false"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.561"
        app:layout_constraintStart_toStartOf="parent"
        tools:layout_editor_absoluteY="191dp">
        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorPrimaryDark" />

    </com.google.android.material.card.MaterialCardView>