ApmeM / android-flowlayout

Linear layout, that wrap its content to the next line if there is no space in the current line.
2.03k stars 371 forks source link

Support for 'RecyclerView' #59

Open ApmeM opened 8 years ago

ApmeM commented 8 years ago

Add support for RecyclerView LayoutManager.

douglasjunior commented 8 years ago

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.

ApmeM commented 8 years ago

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.

douglasjunior commented 8 years ago

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!

dadino commented 8 years ago

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

douglasjunior commented 8 years ago

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.

niqo01 commented 8 years ago

@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 commented 8 years ago

Rolling back to commit 922fcc9e821d838f219c4a5fe5c11bfa0ce70313 fixes the issue

niqo01 commented 8 years ago

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

eshkoliGilad commented 8 years ago

Any updates on FlowLayoutManager ?

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

@ApmeM

douglasjunior commented 8 years ago

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

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

eshkoliGilad commented 8 years ago

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 ?

pzhangleo commented 8 years ago

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

icodeyou commented 7 years ago

@eshkoliGilad hi. Have you fixed this issue ?