WassimBenltaief/FlowLayout

why override addview() method?

Closed this issue · 2 comments

Hi, your project is great.

When I study your code, I found you override public void addView(View child, int index, ViewGroup.LayoutParams params).

I don't know why you did it, so I comment this method. Then there is a strange situation appear.

This is my layout.

<com.beltaief.flowlayout.FlowLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/statusLayout"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

    <TextView
        android:layout_gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="HELLO WORLD" />
</com.beltaief.flowlayout.FlowLayout>

I comment addView() method and invoke FlowLayout.setMode(Mode.PROGRESS), I can see that both progress layout and TextView show in the screen. But what I want is: only the progress layout can show.

so, why should override public void addView(View child, int index, ViewGroup.LayoutParams params) ?

I am sorry for my poor english.

Thank you.

Hi owenmike, thanks for writing for the issue.

This is what the xml of the customView looks like :

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout android:id="@+id/content_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <FrameLayout android:id="@+id/empty_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <FrameLayout android:id="@+id/progress_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <FrameLayout android:id="@+id/connectivity_view"
        android:visibility="gone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</merge>`

It contains four frames. One of them is the content view, means the view that is not progress, neither error or empty. So what you put as a child of FlowLayout in xml will be added to this specific FrameLayout "@+id/content_view". 

In your case, the TextView is your content and will be assigned to the FrameLayout "@+id/content_view" by overriding addView(). what addView() do is to say that you would like to do something else with the content passed in xml.

In order to understand more this how the layout View hierarchy looks like with overriding addView and without :

![With](https://cloud.githubusercontent.com/assets/6058050/19231541/d223c5ac-8eda-11e6-9759-8979c32d7360.png)

In this case what you put inside the FrameLayout, your TextView will be assigned as a content of a specific FrameLayout (@+id/content_view) and will permit the customView class to change its visibility.

![Without](https://cloud.githubusercontent.com/assets/6058050/19231540/d22171b2-8eda-11e6-8c30-d7c1b1f72a12.png)

In this case the content is assigned as the last child of FrameLayout and will not be able to change it's visibility.

Thank you very much. I got it