Git Product home page Git Product logo

flowlayout's Introduction

FlowLayout

FlowLayout is an opensource Android library that alows developers to easily integrate flow layout into their app. FlowLayout is an layout that display its children in multiple rows depending on their size.

Build Status Maven Central Android Arsenal

Example

Framed example screenshot Source code with examples is included in repository.

Dependencies

Gradle

compile "com.wefika:flowlayout:<version>"

Maven

<dependency>
    <groupId>com.wefika</groupId>
    <artifactId>flowlayout</artifactId>
    <version>[version]</version>
</dependency>

Usage

<com.wefika.flowlayout.FlowLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="start|top">

	<View
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Lorem ipsum" />

</com.wefika.flowlayout.FlowLayout>

License

Copyright 2013 Blaž Šolar

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

flowlayout's People

Contributors

blazsolar avatar ryanramchandar 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  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

flowlayout's Issues

Buttons are not adding as per the Flow layout behaviour

I used Flowlayout in my application. Below is my code

<com.wefika.flowlayout.FlowLayout android:id="@+id/flow" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="start" />

then I adding the childview as buttons dynamically.Below is the code
`FlowLayout ll = (FlowLayout)layout.findViewById(R.id.flow);
for (int i = 0; i <= btnList.size; i++) {

          final Button btnTag = new Button(MainActivity.this); 
         btnTag.setId(3000 + i);
        FlowLayout.LayoutParams layoutParams = new FlowLayout.LayoutParams(
               FlowLayout.LayoutParams.WRAP_CONTENT,FlowLayout.LayoutParams.WRAP_CONTENT);
          layoutParams.setMargins(7,7,7,7);
          btnTag.setTextColor(Color.BLACK);

          btnTag.setText("#"+btnList.get(i).toString());
          ll.addView(btnTag,layoutParams)
      }`
  1. Button width is not changing dynamically as per the text
  2. How to decrease Padding between button border and its text.
    How to resolve the above issues?
    Below is my screenshot
    screenshot_2016-08-13-19-33-09

View doesn't re measure when chaning visibility of children

Hey there love the layout, it's super handy. Although I have one problem:

When changing the visibility of the all layouts children to gone, then back to visible at a later time, the layout doesn't remeasure itself and stays flat. The layout is set to wrap_content so I can get it to hide, but it never returns. I'm using this functionality for a popup style of menu.

Any help would be greatly appreciated.

margin child doesn' t take effect

If I have structure like this:

FlowLayout [ LinearLayout->TextView + ImageView]

What I have to do to set margin to a LinearLayout?
I tried something like sample in your project:
FlowLayout.LayoutParams params = new FlowLayout.LayoutParams(FlowLayout.LayoutParams.wrap_content,FlowLayout.LAyoutParams.wrap_Content);
params.rightMargin = 10;
LinearLayout.setLayoutParams(params)

but nothing happened. If I use LinearLayout.LayoutParams it return a cast exception.

Can u please give me an help?
Thanks.

Error when building

Adding this component to build.gradle results in this error:

`Execution failed for task ':app:transformClassesWithJarMergingForDebug'.

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/jetbrains/annotations/Nullable.class`

i get a class cast excepction?

hi i get this error when i try to use the layout

06-07 22:18:36.327  21398-21398/ian.marxbrothers E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: ian.marxbrothers, PID: 21398
    java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.view.ViewGroup$MarginLayoutParams
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5454)
            at com.wefika.flowlayout.FlowLayout.onMeasure(FlowLayout.java:109)
            at android.view.View.measure(View.java:17430)
            at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:727)
            at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:463)
            at android.view.View.measure(View.java:17430)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
            at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
            at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1083)
            at android.widget.LinearLayout.onMeasure(LinearLayout.java:615)
            at android.view.View.measure(View.java:17430)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
            at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
            at android.view.View.measure(View.java:17430)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
            at android.support.v7.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:453)
            at android.view.View.measure(View.java:17430)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
            at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
            at android.view.View.measure(View.java:17430)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
            at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
            at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
            at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
            at android.view.View.measure(View.java:17430)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
            at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2560)
            at android.view.View.measure(View.java:17430)
            at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2001)
            at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1166)
            at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1372)
            at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
            at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
            at android.view.Choreographer.doCallbacks(Choreographer.java:580)
            at android.view.Choreographer.doFrame(Choreographer.java:550)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Gutter for childs

Is there any way to set the gutter for the Flowlayout? Every child view could then have a margin / padding of 10dp and it'd make styling easier.

What if only one child?

I think I have found a bug when there is only one textview added from code to the layout with height= wrap_cotent, then layout will not show since the height is zero in onMeasure method.

Add view at runtime

I am trying to add view at runtime, but it's not working properly.

TextView textView = new TextView(context);
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
textView.setBackgroundColor(Color.GRAY);
textView.setText("New Item");
flowLayout.addView(textView,layoutParams);

Item show with animation

Hi. First of all I would like to thank you such a great piece of code. Its really useful.

I have a concern. I want to show the children/items of FlowLayout with animation. All the items should not animate together instead they should animate one by one in the order of their position. I want to apply scale animation on items.

How can I achieve this? Please help me out

Refer this video for reference.
https://material-design.storage.googleapis.com/publish/material_v_4/material_ext_publish/0B08MbvYZK1iNTGRLb2Zud2RUNFE/animation-meaningfultransitions-hierarchicaltiming-4do_large_xhdpi.webm

Update Gradle Documentation to 0.3.3

0.3.0 Has a big problem with class of FlowLayout.LayoutParams.

Seems to have been fixed though in 0.3.3 but documentation still points to 0.3.0.

FlowLayout not displayed in Android 4.2.2

Hi and thanks for all you have done.
I used your FlowLayout mod, but it works perfectly on Android 2.2, 4.1 also, but on my N4 with 4.2.2, this is not displayed, and I do not know why. Precisely when displaying others views than Button.

Hope you can help !

Kind regards

Gravity issues

The layout_gravity="right" and layout_gravity="left" (or start/end) don't work for children of a FlowLayout.

Add FlowLayout from code

I want to add some features to FlowLayout so I create a custom class and extends it from FlowLayout. then I need to instantiate it and add it to FrameLayout with addView. Is this possible or I should only use xml? I tried and nothing appeared in my screen. Thanks in advanced.

I think when the child‘s width is wrap_content we should add a condition,so the Measure mode is AT_MOST for child

        if(lp.width == LayoutParams.MATCH_PARENT) {
            childWidthMode = MeasureSpec.EXACTLY;
            childWidthSize -= (horizontalMargin);
        }
        // ****for  wrap_content condition 
        else if(lp.width == LayoutParams.WRAP_CONTENT){
            childWidthMode = MeasureSpec.AT_MOST;
            childWidthSize = sizeWidth-horizontalMargin-widthUsed;
        }

        else if(lp.width >= 0) {
            childWidthMode = MeasureSpec.EXACTLY;
            childWidthSize = lp.width;
        }

after:
screenshot_2016-06-28-14-56-56

Set max lines on FlowLayout

How can we set max lines on the FlowLayout. Say for example if we need to show only first 3 lines, can you help me how to achieved this.

Flow layout Ignores padding when laying out children

When a padding is applied to the actual flow layout, it appears to be ignored.

The children in the far left position in column show be laid out at paddingLeft / paddingTop start position.

<com.wefika.flowlayout.FlowLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="@drawable/navigation_drawer_group_row_secondary" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="@dimen/margin_large" android:paddingRight="@dimen/margin_large" android:paddingLeft="@dimen/margin_large"> </com.wefika.flowlayout.FlowLayout>

Right side getting cut off

I am using the FlowLayout in a ScrollView and the right side of the layout is getting cut off. Not sure if this is related it to being in a ScrollView or not.

The last entry is getting cut off too.

I am programmatically adding TextViews to the FlowLayout:

private void updateMoviesTvTags() {
    moviesTvContainer.removeAllViews();

    for (int i = 0; i < 50; i++) {
        CustomTextView tag = new CustomTextView(getActivity());

        FlowLayout.LayoutParams lp = new FlowLayout.LayoutParams(FlowLayout.LayoutParams
                .WRAP_CONTENT, FlowLayout.LayoutParams.WRAP_CONTENT);
        lp.setMargins(0, 0, 10, 10);
        tag.setLayoutParams(lp);

        tag.setBackground(getResources().getDrawable(R.drawable.tag_bg));
        tag.setText("test");
        tag.setTextSize(16);
        tag.setTextColor(getResources().getColor(R.color.primary_blue));
        tag.setPadding(10, 10, 10, 10);
        moviesTvContainer.addView(tag);
    }
}

<com.wefika.flowlayout.FlowLayout
                android:id="@+id/movies_tv_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="start|top"
                android:padding="10dp"/>

screenshot_2015-05-28-21-12-34

Center Justify

Would love to see a center justified option for this FlowLayout! I'd create a pull request, but just don't have the time right now.

MaxHeight on FlowLayout

How do you set a maxHeight on the FlowLayout? Ideally I would have the FlowLayout set to android:layout_height="wrap_content" in xml, and then have a way to set the maxHeight of this FlowLayout.

Ignore right/end padding of last child in a line

Ignoring the right/end padding of the last child can allow more children to fit on a line.

A workaround for now is to reduce the right/end padding of the FlowLayout to offset the child right/end padding.

device-2015-03-09-165230

Failed to resolve: com.wefika:flowlayout

Android Studio 2.0 giving error

Failed to resolve: com.wefika:flowlayout:0.5.0

I tried following versions with no success:

compile 'com.wefika:flowlayout:0.5.0-SNAPSHOT'

second time:

compile 'com.wefika:flowlayout:0.5.0'

Set margin programatically not work

If I set the margin by code instead of xml, there is no margin show up. here is the code. searchHistory is the type of FlowLayout

private void loadSearchHistoryFromDB() {
        ArrayList<String> keyWords = myDatabase.getAllBeitieSearchHistory();
        for (final String keyword: keyWords) {
            TextView textView = new TextView(getActivity());
            textView.setText(keyword);
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
            textView.setBackgroundResource(R.drawable.tag_text);
            textView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    searchBeitieInDB(keyword);
                }
            });

            ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            lp.leftMargin = 15;
            lp.rightMargin = 15;
            lp.topMargin = 15;
            lp.bottomMargin = 15;

            searchHistory.addView(textView, lp);
        }
    }

FlowLayout doesn't display when inside ScrollView

It seems like in some circumstances, FlowLayouts with android:layout_height="wrap_content" disappear when nested inside ScrollViews.

The example below does not display properly, either on the device or in the Android Studio layout editor - the FlowLayout is hidden (looks like it has height 0). If the FlowLayout is given android:layout_height="50dp", it works (but defeats the purpose...). If the outer ScrollView is removed, making the LinearLayout the root, it displays properly.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin">


        <com.wefika.flowlayout.FlowLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="start|top"
            android:minHeight="50dp">

            <Button
                android:id="@+id/button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="New Button" />

            <Button
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="New Button" />

            <Button
                android:id="@+id/button2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="New Button" />

            <Button
                android:id="@+id/button3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="New Button" />
        </com.wefika.flowlayout.FlowLayout>


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello world" />

    </LinearLayout>
</ScrollView>

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.