Closed or-dvir closed 7 years ago
@or-dvir so I see a few things which might lower performance. Setting the LayoutParams each time might result in an additional measure pass which makes things slower. So if you can avoid that it would be good.
In general setting the textSize or textColor shouldn't do too much harm if it stays the same as I guess the TV already optimizes it. I am just a bit surprised that you manually set small, medium or large. Just set a specific textSize using "sp" and you are fine. The user can anyways define in the phone settings how large he want the text to be displayed. It shouldn't be a app setting.
regarding the adapter. As you are not able to prevent setting the adapter, i'd still suggest that you look into the prefetching of items in the RV. (That's not adapter related):
LinearLayoutManager.setInitialPrefetchItemCount(N)
(Search for it in the changelog and read more in their docu: https://developer.android.com/topic/libraries/support-library/revisions.html)
@mikepenz about the LayoutParams thing: the user have an option to add a checkbox to a list (see pictures from the google play store) and she/she can show or hide the check boxes whenever they wants. therefore similarly to the text size thing, i need to check it when the view is being displayed in "bindView()" or else if the user has selected "show check box" from the menu, a view without a checkbox might be recycled. the checkbox is aligned to the right of the screen and so are the other views (e.g. spinner). so i must check it every time and change the layoutParams at runtime otherwise they will overlap. i could probably wrap all those views in a horizontal linearlayout, however im not sure if it will actually help because i dont know if a linearLayout simply does the same thing behind the scenes...
about the settings: i like giving the user a choice. what if the size i choose is too small for the user? he would have to leave the app, go to the phones settings, look for the right one, change it, and then come back to the app. also this will affect all the texts on his phone (only because of the size i chose in my app) - thats why i have it as a local setting.
while i agree that those things do affect performance, all of the those things are also done to every other type of list i have and there are no scrolling problems there - for some reason only the list with the spinner is suffering performance problems (even when i disable these options).
*i will look into the link you sent me later today
ok i have look in the link you posted and it refers to nested recycler views, and also raises a bunch of questions:
LinearLayoutManager.setInitialPrefetchItemCount(N)
?
i assume i would have to make a custom Spinner, find in the source code where they apply the LayoutManager and override that method.all of this sounds like a lot of work... and it might not even help @mikepenz dont get me wrong, i appreciate your help and finding this link for me. im just not sure it is the best solution... any other ideas?
About the text size. The Material Design Guidelines define exact values to use. Those should be used through all apps, so in fact the user most likely adjusted the text size in the past on his phone. But that was just a suggestion, if you think it gives some advantage its fine.
Regarding the link I posted. Yes it refers to RecyclerView, but pre-loading next items ahead of time should also improve scrolling for other types which need to display a list. and are a bit more expensive. As of the usage of it, please refer to the docs as it is not related to the adapter.
Well That are all things I can directly mention. I don't think you have many other options. Possibly using something else than a spinner. Or checking directly what people suggest how to use a spinner in a recyclerView. That are basically all non FastAdapter related issues, as it is a general problem then.
@mikepenz after further experimenting the problem is indeed the adapter. i mean not the adapter itself, but what you said about nested lists/recyclerViews. i tried changing the number of items in the spinner to see where the "break point" is, but even with just 1 item in the adapter scrolling is slow. only when i completely disabled the adapter (as in empty spinners) scrolling was smooth and fast.
thank you so much for you help. even though it turns out not to be a FastAdapter issue you helped me find the answer
hi in my app i have various types of lists. for example: a list with edit text(s), spinner, checkbox etc (as can be seen in the screenshots of the google play store). everything works fine except that in the list with the spinners, if you have a lot of items (say about 30 or more) scrolling is slow/jittery/jumpy. my initial thoughts were that my bindView method is doing too much work and making scrolling slow because it is called lots of times. for example i have a settings/preferences which lets the user set the size of the text, and as far as i can tell (please correct me if im wrong) i have to set the text size programmatically inside bindView and not when the viewHolder is being created. this is because if the user changes the text size and then scrolls down the list, a previous viewHolder will be recycled with the old textSize value. so basically everytime bindView is called, i have to check sharedPreferences for the text size setting, check which setting is enabled (i have 4 options), and then apply it to the textView and spinner at run time. so like i mentioned, i suspected that this is the problem because that sounds like a lot of work to do every time bindView is called.
HOWEVER,
-any idea why scrolling is slow only when i am using a spinner? (maybe it has to do with creating and setting the adapter at runtime? i also have a setting for that...) -was i correct in my explanation above about setting the text size inside bindView instead of when creating the viewHolder?
i assume you'd like to see some code but i don't have access to it right now, so im posting this in the hopes that i was clear enough in my explanation to perhaps get an answer without it (i will edit this post with my code when i have access).
EDIT
here is my object which i attach to the adapter:
here is my custom spinner adapter to change the spinner text size:
and here is the method ActivityMain.setTextSizeAndColor():