简体   繁体   English

scroll Complex最佳实践中的Android Complex项目列表

[英]Android Complex list of items in scrollview Best Practices

I´m developing an app in which I have a list of products, sometimes are a huge list and other times are only one or two items. 我正在开发一个应用程序,其中我有一个产品列表,有时是一个巨大的列表,其他时间只有一两个项目。

I read this items from a local database, right? 我从本地数据库读取这些项目,对吧? ok, when I have about 20 o 30 items, I think the return is very slow, it takes one or two seconds rendering items and I need to know the best practices about that. 好吧,当我有大约20个30项时,我认为返回非常慢,需要一两秒钟渲染项目,我需要知道有关它的最佳实践。 I have tested two ways: 我测试了两种方法:

  • The more tricky (I think), is creating views programmatically and adding to the scrollview as childs of the linearlayout inside. 更麻烦(我认为),是以编程方式创建视图并添加到scrollview作为linearlayout的子项内部。
  • The best for design: having an item-theme in a xml and inflating once by each item. 最适合设计:在xml中有一个item-theme,每个项目都有一次膨胀。

Is there a better way? 有没有更好的办法? I´m sure yes! 我确定是的!

My items are a little bit complex: image, name, category, provider, price, some buttons with "onclick" listeners, two little icons. 我的项目有点复杂:图像,名称,类别,提供商,价格,一些带有“onclick”听众的按钮,两个小图标。 Everything each item. 每个项目的一切。

It is very important for me to speed up that process. 加速这个过程对我来说非常重要。

you can use listview and use the attr : android:descendantFocusability=”blocksDescendants” 你可以使用listview并使用attr:android:descendantFocusability =“blocksDescendants”

it can make your item widget respond some click or touch 它可以使您的项目小部件响应一些点击或触摸

My first thoughts on what you described are: 我对你所描述的内容的第一个想法是:

  • Create an xml layout for the listing 为列表创建xml布局
  • When you get the full list of items, store listing data somewhere 当您获得完整的项目列表时,将列表数据存储在某处
  • Inflate 5 (or 10 or whatever a reasonable amount of might be) listing layouts into the scroll view and use the data to fill them 将列表布局中的5(或10或任何合理数量的可能)膨胀到滚动视图中并使用数据填充它们
  • Use a listener to check when the user has scrolled to the bottom of the scroll view... or halfway down or whatever you choose 使用侦听器检查用户何时滚动到滚动视图的底部...或中途向下或您选择的任何内容
  • Inflate the next set of items if they exist 如果存在,则膨胀下一组项目

This should prevent the slowdown and if you implement it correctly the user won't even know they aren't all loaded. 这应该可以防止速度减慢,如果你正确实现它,用户甚至不知道它们都没有被加载。

I think you need to implement a scroll view type to do this... do some searching for the scrollviewlistener. 我认为您需要实现滚动视图类型来执行此操作...执行一些搜索scrollviewlistener。

It should be pretty straight forward. 它应该很直接。

I found the answer . 我找到了答案 Really cool. 真的很酷。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM