GithubHelp home page GithubHelp logo

Comments (11)

ApmeM avatar ApmeM commented on August 20, 2024

Hi,

I am sorry, I do not understand what do you mean.
System do support dynamic elements adding.
Can you please show me your code that is not working correctly?

Thanks.

from android-flowlayout.

zhumingu avatar zhumingu commented on August 20, 2024
    ViewGroup myViewGroup = (ViewGroup) this.findViewById(R.id.myviewgroup);

    LayoutInflater mInflater = LayoutInflater.from(this);

    for(int i = 0 ; i<5;i++){
        Button button = null;
        if(i%2==0){
            button = (Button)mInflater.inflate(R.layout.button, myViewGroup, false);
            button.setText("偶数"+i);
        }else if(i%3==0){
            button = (Button)mInflater.inflate(R.layout.button, myViewGroup, false);
            button.setText("奇数奇数"+i);
        }else{
            button = (Button)mInflater.inflate(R.layout.button, myViewGroup, false);
            button.setText("超长的超长的超长的"+i);
        }

        myViewGroup.addView(button);

//................................................................

Some of its properties will not work,for example, margin.

from android-flowlayout.

tunjid avatar tunjid commented on August 20, 2024

I have the same issue. When added dynamically, no margins appear. All items are mashed together.

<TextView
    android:id="@+id/text_view"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="left|center_vertical"
    android:layout_margin="@dimen/half_margin"
    android:padding="@dimen/half_margin"
    android:scrollbars="vertical"
    android:textColor="@color/primary" />
    private void populateTextViews(FlowLayout flowLayout, List<Item> items) {

        TextView textView;

        try {
            for (int i = 0; i < items.size(); i++) {
                final Item item = items.get(i);

                textView = (TextView) LayoutInflater.from(flowLayout.getContext())
                        .inflate(R.layout.textview_base, flowLayout, false);

                final String text =  item.getCategory().getName();

                textView.setText(text);

                FlowLayout.LayoutParams layoutParams
                        = new FlowLayout.LayoutParams
                        (FlowLayout.LayoutParams.WRAP_CONTENT, FlowLayout.LayoutParams.WRAP_CONTENT);

                flowLayout.addView(textView, layoutParams);
            }
        }
        catch (Exception e) {
            Constants.ignoreError(e);
        }
    }

from android-flowlayout.

tunjid avatar tunjid commented on August 20, 2024

A temporary fix is wrapping the TextView in a FrameLayout. The library respects the FrameLayout for some reason.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="@dimen/quarter_margin">

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left|center_vertical"
        android:background="@drawable/category_label_light"
        android:scrollbars="vertical"
        android:textColor="@color/primary" />
</FrameLayout>

from android-flowlayout.

kitoaguila avatar kitoaguila commented on August 20, 2024

I can confirm this issue, when adding views programmatically to the FlowLayout, margins are not considered. No matter if it is a textview or a FrameLayout.

@tunjid your solution works because you define the padding in the FrameLayout, not the margin, and paddings are respected.

from android-flowlayout.

Wavesonics avatar Wavesonics commented on August 20, 2024

Confirmed, adding views dynamically causes very broken placement of the children.

from android-flowlayout.

loolooii avatar loolooii commented on August 20, 2024

Just add margins dynamically to whatever view you are using in your FlowLayout:

final Button button = new Button(this);
FlowLayout.LayoutParams params= new FlowLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                            ViewGroup.LayoutParams.WRAP_CONTENT);
params.setMargins(0, 20, 20, 0); // change this to your liking
button.setLayoutParams(params);
yourFlowLayout.addView(button, 0); // change this to your own FlowLayout

This works for me.

from android-flowlayout.

julioz avatar julioz commented on August 20, 2024

I'd love to see a fix for this. Temporarily, loolooii's solution works.

from android-flowlayout.

sanpark avatar sanpark commented on August 20, 2024

@loolooii Thanks.Your solution works for me。

from android-flowlayout.

atearsan avatar atearsan commented on August 20, 2024
TextView view = getLayoutInflater().inflate(R.layout.item_tag_newline, null);
FlowLayout.LayoutParams p = new FlowLayout.LayoutParams(300, 150);
p.newLine = true;
view.setLayoutParams(p);
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:f="http://schemas.android.com/apk/res-auto"
        android:id="@+id/tag"
        android:layout_width="100dp"
        android:layout_height="34dp"
        android:layout_gravity="center"
        android:layout_margin="5dp"
        android:background="@drawable/bg_tag_orange_selector"
        android:gravity="center"
        android:padding="10dp"
        android:paddingBottom="5dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:paddingTop="5dp"
        android:text="TAT"
        android:textColor="@drawable/textcolor_white_selector" />
</FrameLayout>

i write like this, is works.

from android-flowlayout.

ApmeM avatar ApmeM commented on August 20, 2024

Hi, I have created a test for this issue (please check the latest commit).

  1. I have taken comment from @tunjid and found that in latest version it works fine (and also it took margin correctly).

In your example you are rewriting layout margin that is in you inflating layout by doing this:

            FlowLayout.LayoutParams layoutParams
                    = new FlowLayout.LayoutParams
                    (FlowLayout.LayoutParams.WRAP_CONTENT, FlowLayout.LayoutParams.WRAP_CONTENT);

            flowLayout.addView(textView, layoutParams);

If you remove this layoutParams - it will take correct values from inflated layout.

  1. wrapping it with one more layout will just hide the problem with overwrited parameters.
  2. I still can not reproduce issue from @zhumingu as there is no examples of layout itself.

from android-flowlayout.

Related Issues (20)

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.