非接触式应用程序一样scrollinglist在Android应用程序、非接触式、Android、scrollinglist

2023-09-05 09:39:43 作者:bigotry[偏执]

我在写我的第一个Android应用程序(我是一个小白的机器人,但像样的是java)。该应用程序的第一个屏幕由一个巨大的漫画,对象列表(约1.5K项目)。在code我用的是如下:

I'm writing my first android app (I'm a noob at android, but decent at java). The first screen of the app consists of a huge list (about 1.5K items) of Manga-objects. The code I use is as following:

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>

然后,我有一个适配器,它基本上需要一个漫画对象,并把它的名字中的TopText行,并且它在bottomtext最新的更新日期。然而,(这可能是由该单元的虚拟化,虽然引起的),结果是很慢的。滚动列表需要永远和你只能滚动的时间小撕成小块。我怎样才能让像在联系人,应用程序列表中的工作?所以,当你开始滚动手柄弹出右侧的画面,当你拖动字母显示为有多远,你已经滚动(名单按字母顺序排序),而且,是有办法,我可以改善表的性能?

Then I have a adapter which basically takes a Manga-object and puts it's name in the rows toptext, and it's latest updated date in the bottomtext. However, (this might be caused by the virtualization of the unit though), the result is really slow. Scrolling the list takes forever and you can only scroll small peaces of the time. How can I make the list work like the one in the contacts-app? So that when you start scrolling a handle pops out at the right side of the screen, and when you drag it letters shows up as of how far you've scrolled (the list is sorted alphabetically), and also, is there a way I could improve the performance of the list?

推荐答案

要添加的拇指滚轮,调整你的ListView在main.xml中像这样:

To add the thumb scroller, adjust your ListView in your main.xml like so:

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

添加机器人:fastScrollEnabled =真正的属性

http://developer.android.com/intl/de/reference/android/widget/AbsListView.html#attr_android:fastScrollEnabled

您也可以看看使用SectionIndexer

You may also look at using a SectionIndexer

http://developer.android.com/intl/de/reference/android/widget/SectionIndexer.html