Android ListView 不滚动。什么都试过了
Android ListView does not scroll. Tried everything
好的,我有一个不滚动的 listView。我尝试了在 SO 上提出的所有问题。
1- 我在列表中有足够的项目使其可以滚动。
2- 它不在 ScrollView 中。
3- 我尝试将其高度更改为 wrap_content 和 match_parent
4- 我在列表视图中有一个图像,我将 focusable 设置为 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"
>
请帮我解决这个问题。
像这样将 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"/>
在您的 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">
好的,我有一个不滚动的 listView。我尝试了在 SO 上提出的所有问题。
1- 我在列表中有足够的项目使其可以滚动。
2- 它不在 ScrollView 中。
3- 我尝试将其高度更改为 wrap_content 和 match_parent
4- 我在列表视图中有一个图像,我将 focusable 设置为 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"
>
请帮我解决这个问题。
像这样将 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"/>
在您的 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">