I got a list view that shows a standard image text items, I use the standard ArrayAdapter to work with the view.
My problem is that the scrolling get stuck and not very smooth.
I done some profiling, and found that most of the time a Measure operation is in progress(for many controls most of them are containers)
Is it possible to make stuff work faster? where to start?
Here is very nice presentation about ListView performance http://www.google.com/events/io/2010/sessions/world-of-listview-android.html
Edit: This article may also help http://www.curious-creature.org/2009/02/22/android-layout-tricks-1/
Related
I have a Custom Adapter for the ListView. The Layout has three images, some text. When loading the Listview, it takes a while, because of the images. Its something like Posts.
Same app in iOS is loading very fast, I think that UITableView works different than Listview.
Is there a way, in place to load all posts, only load for example 3 posts and when the user scrolls the Listview down, load the next 3, scroll down, load the next 3 and so on. This could give a better performance.
Normally, android listview work that way. Let's say there are 5 views that user can reach at the moment. ListView creates 9 views and when user scrolls it loads the bottom ones. You can think it this way. Your main problem is how are you loading your images and create the custom view. There is a common pattern for custom adapters which handles the fast recycling views(ViewHolder pattern). You should checkout the link for ViewHolder pattern. https://www.javacodegeeks.com/2013/09/android-viewholder-pattern-example.html
It probably loads slow because the images should be resized every time, if you could save thumbnails it would go much faster.
Have you tried to use Recycler View instead? As long as I know using the Recycler View is the best practice nowadays. You can find a very good tutorial here:
http://www.vogella.com/tutorials/AndroidRecyclerView/article.html
You use the Recycler View almost the same way you do with List View: adapter, viewHolder, etc. It's good to mention though that you need to pay special attention to the use of the LayoutManager since the Recycler View it itself doesn't "know how to draw" the stuff on the screen.
I created a gridview with a custom ArrayAdapter. Inside of the gridView is a couple of TextViews, an EditText and a Spinner. Everything was going fine until I added listeners to the Spinner and the EditText. Aside from the trouble of getting these to work (a lot of issues with the recycling) now it is lagging quite heavily. I read around and it seems that this is an inherent issue.
There is up to 16 items. Doing this manually in a Gridlayout or something would cause a ton of manual repeated work, which is why I went with a GridView and adapter. But the performance issues is a major problem.
So is there a way I can duplicate the functionality of a GridView without the issues that I am running into?
If someone thinks they can solve my performance issues with the current code I am happy to post. It is pretty standard ArrayAdapter using the viewholder pattern. Thanks
UPDATE:
Ok, so I ended up just going with the RecyclerView using the pattern laid out in this accepted answer Saving EditText content in RecyclerView After some tweaking to my code I have gotten rid of the lag.
Why dont you use a RecyclerView? It is meant for situations where you need to do a large number of calls to repeated patterns like in your gridview. It is much more efficient than gridview/listview for complex layouts.
You can try using TableLayout and see if it improves things. You can add all your rows as rows of TableLayout.
TableLayout
Hello
Thanks for checking my topic out! I will not go into depth why I have created this component, but safe to say for my specific application it was needed :)
The component is quite large so i used pastebin for this occation: http://pastebin.com/6jcmySr3
The problem
The issue here is not what you perhaps expected. The component works just great as a external GridView component to be used in a external ScrollView compared to the original one that android offers. Scroll normally and it will update the adapter Items correctly to the location you expected them to have. The issue I am having, is that if you scroll too fast the new location of the item might end up to be wrong and I can not figure out why.
My guess thus far have been that the newItemLocation-variable updates too fast when you scroll and the location where the view should have been moved is wrong, or that the view-update logic through getView updates too slow. In which case, I don't really have a solution for any of them. Could someone point me into the right direction?
Thanks!
*Edit: I am also using a ViewHolder pattern in my Adapter, so it's not because of that :)
I got the similar issue like you, the grid view will become empty or other strange cases(like display only one side without the other side when using etsy-like StaggeredGrideView), so I find a possible solution that can highly reduce the chance occurring this problem, you can try to set the min height of your TextView like android:minLines="n" or android:singleLine="true" in your GridView items(if you). That means the problem may be occurred when rendering the height of the TextView. Just try it~ =)
You can refer this post as well ==> Android: Gridview going blank while scrolling fast
I know it may be weird that I want to succeed.
Let me explain whole in details. Firstly, I want to use two ListView looking in an Activity screen. Just like how Pinterest looks like. (I'm not sure is it true but it's named as heterogeneous gridview.) There is also one thing that I needed to implement: lazy loading. There are about 30 images in my activity, so that's not good to fetch all images at one time. That's why I needed lazy load.
So in first, I pondered on that I how obtain that appearance, I mean heterogeneous gridview. Then decided to add to LinearLayout in a ScrollView. Linears have vertical orientation. With thay approach, I added my new views by using odd-even method in Linear Layouts.
Althought, there weren't any adapter so according to my knowledge, there is no way to controll which items would be displayed. So lazy load is not suitable.
I've also tried two ListView in an Activity, but got some lag and also synchronous scroll problems. On the other hand it has a bad recycling.
So in this scenario, I want to ask is there way to fill LinearLayouts using Adapter? Or what would you recommend to create a heterogeneous gridview but also with lazy load.
If my approaches are wrong, I would not hasitate to change it.
Any clue would be great for me. If there is something unclear, please specify it. I'll explain with more details.
After a lot of research, finally I found a library which have lazy loading and heterogeneous gridview and also not has any scroll or recycling lags/problems.
Maurycy's StaggeredGridView is completely what I'm looking for.
Here is the library and also there is a demo too.
If I get your question right, here is what you need: http://spinlist.autsia.com/
I am comparing performances, specifically scrolling speeds of a ListView, of apps that I create, to native Android 4.0 apps - Gmail, Gtalk, etc.
One thing I have noticed is that the scrolling frame rate of a ListView on the native Android apps are very high - almost 60fps. In my apps, a ListView don't scroll nearly as fast.
Assuming I'm using ListView incorrectly (which I'm not - I've followed everything stated here: http://www.youtube.com/watch?v=wDBM6wVEO70), I decided to create a dummy ListView that just returns a dozen almost empty LinearLayout views as it's rows (yes I'm using convertView correctly). What's disturbing here is that my almost blank ListView has slower scrolling performance than any of the native apps - Gmail, Gtalk, Contacts, etc.
As a side note, a simple ScrollView has really good scrolling performance, but it is inadvisable to use a ScrollView for large lists.
Clearly, the native apps are doing something (or have access to something) that I don't understand. Unfortunately these native apps aren't open source. Does anyone have any insight as to how these native apps achieve such tremendous performance?
After look at the source code for the native email application, I have found that the list items in a list of messages are single Views, not ViewGroups like LinearLayout. That makes for a very flat View hierarchy which leads to a better frame rate while scrolling the list. I think I remember watching a video of a talk by Romain Guy (one of the lead Android UI engineers) that mentioned that the Gmail team did something similar to increase performance.
To achieve this yourself, you'd have to subclass View and draw everything in the View yourself in the onDraw() method.
Here is the source for a message list item in the current email application.
They do a cool trick where you inflate a view (but don't attach it), get the coordinates of where the items go based on the ViewGroup it is in, and cache the coordinates in a Map so when a view is recycled in a list you don't have to inflate that view again. I might try this in a future project of mine!
I hope this helps!
There are some techniques to make ListView faster: caching and using dissapeared list items as new list items to avoid long operation of creating them. You need to create your own class based on ListView to realize these techniques. Read more here.
I also followed on that video to build my list view. In my app, there are not much items (rows). But I think if we just do as the video said, we are on right way, at least on the theory?