【问题标题】:Contact-app like scrollinglist on android联系人应用程序,如 android 上的滚动列表
【发布时间】:2010-04-09 11:55:54
【问题描述】:

我正在编写我的第一个 android 应用程序(我是 android 的菜鸟,但在 java 方面还不错)。该应用程序的第一个屏幕包含一个巨大的漫画对象列表(大约 1.5K 项)。我使用的代码如下:

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android">
        <ListView android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:id="@+id/android:list"></ListView>
        <TextView android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:text="@string/list_no_items"
            android:id="@+id/android:empty"></TextView>
</LinearLayout>

row.xml:

<LinearLayout android:id="@+id/LinearLayout01"
              android:layout_width="fill_parent" 
              android:layout_height="?android:attr/listPreferredItemHeight"
              android:padding="6dip"
              xmlns:android="http://schemas.android.com/apk/res/android">
    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginRight="6dip"
        android:src="@drawable/icon" />
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="fill_parent">
        <TextView
            android:id="@+id/toptext"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1"
            android:gravity="center_vertical"
        />
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1" 
            android:id="@+id/bottomtext"
            android:singleLine="true"
            android:ellipsize="marquee"
        />
    </LinearLayout>
</LinearLayout>

然后我有一个适配器,它基本上接受一个漫画对象并将其名称放在顶部文本行中,并且它是底部文本中的最新更新日期。但是,(这可能是由单元的虚拟化引起的),结果确实很慢。滚动列表需要很长时间,而且您只能滚动一小段时间。如何使列表像联系人应用程序中的那样工作?这样,当您开始滚动时,屏幕右侧会弹出一个句柄,并且当您拖动它时,字母会显示您滚动了多远(列表按字母顺序排序),还有,我有没有办法可以提高列表的性能吗?

【问题讨论】:

    标签: android listview


    【解决方案1】:

    要添加滚动条,请在 main.xml 中调整 ListView,如下所示:

    <ListView android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:id="@+id/android:list"
            android:fastScrollEnabled="true"></ListView>
    

    添加android:fastScrollEnabled="true" 属性。

    https://developer.android.com/reference/android/widget/AbsListView.html#attr_android:fastScrollEnabled

    您也可以考虑使用SectionIndexer

    【讨论】:

      猜你喜欢
      • 2012-03-12
      • 1970-01-01
      • 1970-01-01
      • 2020-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多