【问题标题】:Listview not scrolling - why so?Listview 不滚动 - 为什么会这样?
【发布时间】:2019-08-10 06:41:39
【问题描述】:

我无法使用列表视图滚动。我尝试过使用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" />

【问题讨论】:

  • 这个问题可能是使用wrap_content 出现的。你能给0dp你的身高吗?
  • MaterialCardViewListView 应该在 ConstraintLayout 内。

标签: android android-layout listview


【解决方案1】:

请试试这个代码,让我知道它的工作与否

<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" />

【讨论】:

    【解决方案2】:

    尝试将您的列表放入 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-07
      • 2018-10-15
      • 2021-09-22
      • 2011-06-03
      • 2018-06-08
      • 2014-12-21
      • 1970-01-01
      相关资源
      最近更新 更多