android-flowlayout icon indicating copy to clipboard operation
android-flowlayout copied to clipboard

Support for 'RecyclerView'

Open ApmeM opened this issue 10 years ago • 13 comments

Add support for RecyclerView LayoutManager.

ApmeM avatar Sep 24 '15 06:09 ApmeM

Continuing the discussion of #39.


The RecyclerView is a component created to replace the "ListView" and "GridLayout". It works with Adapters and also LayoutManagers.

The Adapters is designed to provide the data source, as well as in the ListView.

The LayoutManagers are responsible for organizing the items on the screen. Standards implementations are: LinearLayoutManager, GridLayoutManager, and StaggeredGridLayoutManager.

See examples here: https://guides.codepath.com/android/Using-the-RecyclerView


One problem that has been found to apply the function "FlowLayout", ie making the number of columns is dynamic, according to the screen size.

To solve, I applied this workaround: http://stackoverflow.com/questions/26666143/recyclerview-gridlayoutmanager-how-to-auto-detect-span-count

Then I had the idea of ​​creating a "FlowLayoutManager", so you can use the RecyclerView and all the advantages it provides. So I asked you if you had plans, because I believe that you can leverage the knowledge applied to FlowLayout.

This would also solve the question #14.


If I can help with anything else, I have little free time, but I am available.

douglasjunior avatar Sep 24 '15 12:09 douglasjunior

Hi,

You may try to use recycler view now. The example is available in FlowLayoutManagerActivity. Because of code restrucutization there can be some breaking changes (not sure what exactly can be broken, but if you were using layout parameters values - they are no longer available)

It is still not using all power of recycler view like scrolling or actual view recycling, but all original FlowLayuot functionality is there.

Thanks.

ApmeM avatar Sep 30 '15 13:09 ApmeM

Yes, I did tests with RecyclerView and it worked great!

The next step really is scrolling and recycling of views.

For example, I have cases in my list has 48 items, but only 2 are displayed at a time. When this runs notifyDataChanged it needs to update the 48 items. It is very slow.

Thanks for your time, it's getting very good, I believe that with that the library will cover a lot of users!

douglasjunior avatar Sep 30 '15 14:09 douglasjunior

Even with view recycling notifyDataSetChanged() will redraw all 48 items. You should use notifyItemChanged(int position) or similar to update just the needed views.

dadino avatar Sep 30 '15 14:09 dadino

In FlowLayoutManager it makes no difference, it will always be updated every item.

In my case, using the FlowLayoutManager is used 40% of CPU to notifyDatasetChanged. Using GridLayoutManager only 10%.

For the GidLayoutManager updates only the items that appear on the screen.

douglasjunior avatar Oct 01 '15 14:10 douglasjunior

@ApmeM just tried master FlowLayoutManager and I am getting:

java.lang.IllegalArgumentException: Called attach on a child which is not detached: ViewHolder{10f1f7e9 position=0 id=0, oldPos=-1, pLpos:-1 no parent}
at android.support.v7.widget.RecyclerView$4.attachViewToParent(RecyclerView.java:587)
at android.support.v7.widget.ChildHelper.attachViewToParent(ChildHelper.java:239)
at android.support.v7.widget.RecyclerView$LayoutManager.attachView(RecyclerView.java:6492)
at android.support.v7.widget.RecyclerView$LayoutManager.attachView(RecyclerView.java:6507)
at android.support.v7.widget.RecyclerView$LayoutManager.attachView(RecyclerView.java:6518)
at org.apmem.tools.layouts.FlowLayoutManager.onLayoutChildren(FlowLayoutManager.java:63)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2847)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3145)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1043)
...

niqo01 avatar Oct 02 '15 00:10 niqo01

Rolling back to commit 922fcc9e821d838f219c4a5fe5c11bfa0ce70313 fixes the issue

niqo01 avatar Oct 02 '15 00:10 niqo01

Also I am having an issue where all the cells width are correct but for two of them, half of the text is not visible due to the text being moved to a new line (Cell 3 and 4 on the screenshot). The cell width look correct though. flowlayoutmanager

niqo01 avatar Oct 02 '15 02:10 niqo01

Any updates on FlowLayoutManager ?

When I use notifyDataSetChanges() or notifyItemChanged() is scrolled back to the top.

@ApmeM

eshkoliGilad avatar Mar 01 '16 11:03 eshkoliGilad

@eshkoliGilad Please, create a new issue for a new question.

Tip: dont mention a user in your question to get attention.

douglasjunior avatar Mar 01 '16 11:03 douglasjunior

This is somewhat related to the issue.

onLayoutChildren is called again when updating the data set and I can't for my life seem to be able to get recycling to work with scroll like in other LayoutManagers.

Any solution for this issue ?

@douglasjunior

Edited: Why not mention user if what I'm writing is referring to him ?

eshkoliGilad avatar Mar 01 '16 11:03 eshkoliGilad

@niqo01 hi, do you find reason for problem with cell3 and cell4? I find same problem too.

pzhangleo avatar Mar 18 '16 09:03 pzhangleo

@eshkoliGilad hi. Have you fixed this issue ?

icodeyou avatar Nov 21 '16 00:11 icodeyou