【问题标题】:Android ListView does not scroll. Tried everythingAndroid ListView 不滚动。尝试了一切
【发布时间】:2016-04-14 00:51:27
【问题描述】:

好的,我有一个不滚动的 listView。我尝试了所有关于 SO 的要求。

1- 列表中有足够的项目使其可滚动。

2- 它不在 ScrollView 中。

3- 我尝试将它的高度更改为 wrap_content 和 match_parent

4- 我在列表视图中有一张图片,我将可聚焦设置为 false。 什么都试过了。我感觉要放弃了。这是我的 fragment_list.xml

    <?xml version="1.0" encoding="utf-8"?>
 <ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/contacts"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:scrollbars="vertical"
android:focusable="true"
tools:listitem="@layout/fragment_contacts" />

这是 fragment_contacts.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
 >

<ImageView
    android:id="@+id/image"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:contentDescription="@string/Description"
    android:focusable="false"/>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="60dp"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="bottom"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textSize="16sp"
        android:textStyle="bold"
        android:layout_marginLeft="14dp"/>

    <TextView
        android:id="@+id/phone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="top"
        android:textSize="14sp"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="14dp" />
</LinearLayout>

如果有问题,现在我会提供额外的信息。 我有 main.xml,里面有一个寻呼机。

<android.support.design.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_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="context">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        />


    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="fixed"
        app:tabGravity="fill"

        />
    <android.support.v4.view.ViewPager
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/backscreen3"
        />


</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main" />

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="context"
tools:showIn="@layout/activity_main"
>

请帮我解决这个问题。

【问题讨论】:

  • 在使用 CoordinatorLayout 时使用 recycleview insted of listview
  • 我猜这是我最后的选择???
  • 你在ScrollView里面用过listview吗?
  • Listview 在一个简单的 LinearLayout 包装器中滚动这是一个简单的例子吗?
  • @UmerAsif ,我想说只是单独测试你的 xml 文件,以检查哪个块给你这个意想不到的结果。远程发现这个错误并不难。

标签: android xml listview android-listview


【解决方案1】:

像这样将ListView 放在RelativeLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ListView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/listview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

【讨论】:

    【解决方案2】:

    在您的 ListView 中设置此属性

      <ListView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:dividerHeight="0dp"
            android:listSelector="@android:color/transparent">
    

    【讨论】:

      猜你喜欢
      • 2012-06-07
      • 1970-01-01
      • 2019-09-19
      • 1970-01-01
      • 2019-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多