在Android的ListView提高滚动平滑度平滑、Android、ListView

由网友(我沒哭只是睫毛溺ㄋ氷)分享简介:我有一个Android 的ListView 有小(比如1-5帧)口吃,因为它是滚动的,大约每秒钟左右。我意识到很多Android手机有这些问题,平滑的动画,但是,在我的手机(摩托罗拉A855运行Android 2.2),本地联系人列表滚动非常顺利。该项目视图中的联系人列表中比项目视图在我的名单,这是比较复杂的:I h...

我有一个Android 的ListView 有小(比如1-5帧)口吃,因为它是滚动的,大约每秒钟左右。我意识到很多Android手机有这些问题,平滑的动画,但是,在我的手机(摩托罗拉A855运行Android 2.2),本地联系人列表滚动非常顺利。该项目视图中的联系人列表中比项目视图在我的名单,这是比较复杂的:

I have a an Android ListView that has small (say, 1-5 frame) stutters as it is scrolling, about every second or so. I realize that many Android phones have these problems with animation smoothness, however, on my phone (Motorola A855 running Android 2.2), the native contact list scrolls quite smoothly. The item view in the contact list is more complex than the item view in my list, which is:

<RelativeLayout>
    <TextView />
    <TextView />
</RelativeLayout>

我仅想达到平滑不如天然联系人列表。看起来这应该是可能的,而不在本地code优化,但也许我错了。

I only want to achieve smoothness as good as the native contact list. It seems like this should be possible without optimizing in native code, but perhaps I'm wrong about that.

我已经尝试了几件事情:我简化了项目视图,甚至进一步,我试图实例化编程,而不是在XML中。我也试着改变我对项目点击事件的反应方式,按照此链接:

I have tried a few things: I simplified the item view even further, and I tried instantiating it programmatically instead of in XML. I also tried changing the way I react to item click events, as per this link:

的http://groups.google.com/group/android-developers/browse_thread/thread/7dc261a6b382ea74?pli=1

所有这些事情似乎都对性能有任何影响。

None of these things seem to have any effect on performance.

有什么我可以在我的应用程序做,以提高性能?我期待部署这个应用程序的一些手机,因此更改设置在手机上或生根的设备是不是在我的情况选择。下面是我的适配器类的getView方法:

Is there anything I can do in my app to improve performance? I'm looking to deploy this app to a number of phones, so changing settings on the phone or rooting the device is not an option in my case. Here is the getView method from my adapter class:

    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater flater = (LayoutInflater)context.getSystemService(ListActivity.LAYOUT_INFLATER_SERVICE);
        layout = flater.inflate(R.layout.song_view, parent, false);
        TextView first = (TextView)layout.findViewById(R.id.firstLine);
        TextView second = (TextView)layout.findViewById(R.id.secondLine);

        Thing t = array.get(position);
        first.setText(t.title);
        second.setText(t.name);
        return layout;
    }

在此先感谢!

Thanks in advance!

推荐答案

这是很难知道为什么这可能会发生,没有看到你的code。

It's difficult to know why this may be happening without seeing your code.

然而,一个寻找的地方是你的getView()方法,在你的ListAdapter(假设你使用一个自定义的适配器)。尝试和再利用多数民众赞成作为参数传递给此方法,而不是创建一个新的每次查看。另外,不要做任何过重这个方法(如网络电话),实际上是尽量做到精益和平均尽可能获得最佳的性能。

However, one place to look is your getView() method in your ListAdapter (assuming you're using a custom adapter). Try and re-use the View that's passed as an argument to this method rather than creating a new one each time. Also don't do anything too heavy in this method (e.g. a network call), in fact try to make it as lean and mean as possible for best performance.

阅读全文

相关推荐

最新文章