GithubHelp home page GithubHelp logo

ch4vi / flowlayout Goto Github PK

View Code? Open in Web Editor NEW
101.0 7.0 10.0 1.15 MB

An Android Layout Manager to create a gridview with cells of different sizes inspired by Flow Layout for iOS.

Home Page: https://github.com/ch4vi/FlowLayout

License: Apache License 2.0

Java 6.72% Kotlin 93.28%
android flowlayout recyclerview kotlin layout manager

flowlayout's Introduction

FlowLayout – Android Layout Manager

Download

A LayoutManager that must be used with RecyclerView inspired by Flow Layout for iOS.

The layout manager places cells on a linear path and fits as many cells along that line as it can. When the layout manager runs out of room on the current line, it creates a new line and continues the layout process there.

Compile

Using Gradle

Requires Min SDK version >= 10

    compile 'com.ch4vi.flowlayoutmanager:flowlayoutmanager:1.0.2'

Using Maven

    <dependency>
      <groupId>com.ch4vi.flowlayoutmanager</groupId>
      <artifactId>flowlayoutmanager</artifactId>
      <version>1.0.2</version>
      <type>pom</type>
    </dependency>

Usage

First of all add a RecyclerView to your layout

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/button_center"
        android:background="@color/e"
        android:scrollbars="vertical" />

Then in your class initialize the RecyclerView, in this case with 3 columns, vertical orientation and the first cell size will be 1x1, the second 2x2...

    val manager = FlowLayoutManager(3, RecyclerView.VERTICAL, object : FlowLayoutManager.Interface {
        override fun getProportionalSizeForChild(position: Int): Pair<Int, Int> {
            return when (position) {
                 0 -> Pair(1, 1)
                 1 -> Pair(2, 2)
                 2 -> Pair(4, 1)
                 3 -> Pair(3, 2)
                 else -> Pair(1, 1)
            }
        }
    })
    recyclerView.layoutManager = manager

Note If we add a cell too big for example if we have 3 columns and we add a cell 4x1, this cell will be ommited in the drawing process.

Optionally you can add a custom space between the cells adding a dimen resource named "default_card_insets" and setting an item decoration to your RecyclerView like in the example

    <dimen name="default_card_insets">8dp</dimen>
    recyclerView.addItemDecoration(manager.InsetDecoration(this))

Demo

Credits

License

FlowLayout is license under the Apache License.

flowlayout's People

Contributors

ch4vi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

flowlayout's Issues

using FlowLayout in java code

how can i to use this good lib in java code

FlowLayoutManager layoutManager=new FlowLayoutManager(3, RecyclerView.HORIZONTAL, new FlowLayoutManager.Interface() {
@OverRide
public kotlin.Pair<Integer, Integer> getProportionalSizeForChild(int i) {
return null;
}
});

it wants kotlin.Pair Object but can not to find it , even i use android.support.v4.util.Pair but is not compatible
how can i to resolve it to using this lib in a java code ?

expected class or package: flowLayoutManager.InsetDecoration

I have below java code as FlowLayout Readme says:

FlowLayoutManager flowLayoutManager =new FlowLayoutManager(spanCount,RecyclerView.VERTICAL,new Interface(){...});

mRecyclerView.addItemDecoration(flowLayoutManager.InsetDecoration(this)); << this line android studio will have a compiler error as the title.

How to fix it? thanks .

i don't know kolin BTW.

Horizontal orientantion scroll not working

Hey,
I've implemented your layout manager for my RecyclerView which is supposed to have horizontal scrolling. The items are drawn and the flow layout works, but I can't make the items scroll horizontally. The flag for orientantion is set to RecyclerView.HORIZONTAL.
Is there a fix to that?

Request: please show how to use with adding more and more views

It is said in the description:

"The layout manager places cells on a linear path and fits as many cells along that line as it can. When the layout manager runs out of room on the current line, it creates a new line and continues the layout process there.
"

Can you please show a sample of putting views programmatically, so that it adds each on the current line, till there is no more space and it goes to the next?

It's just that in the current sample, you define the columns (using getProportionalSizeForChild), and this loses the point of using it, because it should be automatic, as each line could have a different number of views, with various sizes.

Crash when using diffutil

Process: de.tvsmiles.app.debug, PID: 28921
java.lang.IndexOutOfBoundsException: Invalid item position 15(15). Item count:12 android.support.v7.widget.RecyclerView{9b933bd VFED..... .F....I. 0,0-1080,1704 #7f090067 app:id/campaigns_list}, adapter:com.kwizzad.akwizz.homescreen.campaignslist.CampaignsAdapter@2cccdb2, layout:com.ch4vi.flowlayoutmanager.FlowLayoutManager@18c0103, context:com.kwizzad.akwizz.homescreen.HomeActivity@a313088
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5779)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5752)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5748)
at com.ch4vi.flowlayoutmanager.FlowLayoutManager.layoutChildren(FlowLayoutManager.kt:178)
at com.ch4vi.flowlayoutmanager.FlowLayoutManager.onLayoutChildren(FlowLayoutManager.kt:119)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:3763)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3527)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:4082)
at android.view.View.layout(View.java:16636)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:606)
at android.view.View.layout(View.java:16636)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16636)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:132)
at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1361)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:894)
at android.view.View.layout(View.java:16636)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16636)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
at android.view.View.layout(View.java:16636)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16636)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
at android.view.View.layout(View.java:16636)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2678)
at android.view.View.layout(View.java:16636)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2171)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1931)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreograp

Padding support

Hey, guys. I really like this library and I am going to use it in my app, but there is a thing that is missing. I didnt get top padding working with clipToPadding="false"

As I know this thing must be handled by layout manager and not by view itself. So I want to do this feature request to you guys

peace!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.