Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layout is invisible if first item is gone #283

Closed
bashtian opened this issue May 14, 2017 · 8 comments
Closed

Layout is invisible if first item is gone #283

bashtian opened this issue May 14, 2017 · 8 comments
Labels
Milestone

Comments

@bashtian
Copy link

bashtian commented May 14, 2017

I have a layout with multiple children and when I set the first item to View.GONE the whole layout is invisible. If I only set the second item to gone the layout works fine.

There seems to be a problem with calculating flexLine.mItemCount, in this line [0] it's always 1 when the first item is gone.

[0] https://github.com/google/flexbox-layout/blob/dev_recyclerview/flexbox/src/main/java/com/google/android/flexbox/FlexboxLayout.java#L658

@thagikura thagikura added the bug label May 14, 2017
@thagikura
Copy link
Contributor

Thanks for reporting. It's likely a bug with FlexboxLayout

@thagikura
Copy link
Contributor

Hmm,

I tried to reproduce it on my end, but couldn't reproduce it so far.
I changed visibility of the first item in the fragment_flexboxlayout.xml as gone, but the whole layout was still visible in the demo-playground app.

Is it possible to share your reproducible code?

<com.google.android.flexbox.FlexboxLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/flexbox_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:alignContent="flex_start"
    app:alignItems="flex_start"
    app:flexWrap="wrap"
    tools:showIn="@layout/activity_main">

    <TextView
        android:id="@+id/textview1"
        style="@style/FlexItem"
        android:layout_width="@dimen/flex_item_length2"
        android:layout_height="@dimen/flex_item_length"
        android:text="@string/one"
        android:visibility="gone"
    />

    <TextView
        android:id="@+id/textview2"
        style="@style/FlexItem"
        android:layout_width="@dimen/flex_item_length3"
        android:layout_height="@dimen/flex_item_length"
        android:text="@string/two" />

    <TextView
        android:id="@+id/textview3"
        style="@style/FlexItem"
        android:layout_width="@dimen/flex_item_length"
        android:layout_height="@dimen/flex_item_length"
        android:text="@string/three" />

</com.google.android.flexbox.FlexboxLayout>

Thanks.

@bashtian
Copy link
Author

I changed the visibility programmatically from visible to gone on the first item, maybe that could be the problem.

@thagikura
Copy link
Contributor

Hmm,

I change the visibility programmatically but the same result.

I changed the OnClickListener in the FlexboxLayoutFragment
in line 82 as follows (changing the first item's visibility as GONE at the bottom).

      addFab.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    int viewIndex = mFlexContainer.getFlexItemCount();
                    // index starts from 0. New View's index is N if N views ([0, 1, 2, ... N-1])
                    // exist.
                    TextView textView = createBaseFlexItemTextView(activity, viewIndex);
                    FlexboxLayout.LayoutParams lp = new FlexboxLayout.LayoutParams(
                            ViewGroup.LayoutParams.WRAP_CONTENT,
                            ViewGroup.LayoutParams.WRAP_CONTENT);
                    fragmentHelper.setFlexItemAttributes(lp);
                    textView.setLayoutParams(lp);
                    textView.setOnClickListener(new FlexItemClickListener(activity,
                            new FlexItemChangedListenerImpl(mFlexContainer), viewIndex));
                    mFlexContainer.addView(textView);
                    mFlexContainer.getFlexItemAt(0).setVisibility(View.GONE);
                }
            });

@bashtian
Copy link
Author

bashtian commented Jun 1, 2017

Here is a layout where the first item is set to GONE and the last item also disappears.


    <com.google.android.flexbox.FlexboxLayout
        android:id="@+id/flexbox_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:alignContent="flex_start"
        app:alignItems="flex_start"
        app:flexWrap="wrap"
        tools:showIn="@layout/activity_main">

        <TextView
            android:id="@+id/textview1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="1"
            android:visibility="gone"
            app:layout_wrapBefore="true"
            />

        <TextView
            android:id="@+id/textview2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="2"
            app:layout_wrapBefore="true"
            />

        <TextView
            android:id="@+id/textview3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="3"
            app:layout_wrapBefore="true"
            />

    </com.google.android.flexbox.FlexboxLayout>

Maybe the disappearing of the whole layout is related to this bug.

thagikura added a commit that referenced this issue Jun 14, 2017
view is in the second line.

In that case, the position of the second view is misplaced.

Fixes #283
@thagikura
Copy link
Contributor

Thanks for pasting the example layout.
The issue happened in the case where the first view's visibility is gone and the second view's layout_wrapBefore is set to true.

In that case, the second view's position is misplaced.
Sent #300 to fix this. The fix will be submitted to the dev_recyclerview it will be fixed in the master once the dev_recyclerview branch is merged to master.

thagikura added a commit that referenced this issue Jun 14, 2017
…nd view is in the second line. (#300)

In that case, the position of the second view is misplaced.

Fixes #283
@thagikura thagikura added this to the 0.3.0 milestone Jun 14, 2017
@thagikura
Copy link
Contributor

Should be fixed by #300

@bashtian
Copy link
Author

Thank you for the fix. I found another issue that seems to be related. I created a new ticket #303

thagikura added a commit that referenced this issue Jun 15, 2017
…nd view is in the second line. (#300)

In that case, the position of the second view is misplaced.

Fixes #283
thagikura added a commit that referenced this issue Jun 16, 2017
…nd view is in the second line. (#300)

In that case, the position of the second view is misplaced.

Fixes #283
thagikura added a commit that referenced this issue Jun 28, 2017
…nd view is in the second line. (#300)

In that case, the position of the second view is misplaced.

Fixes #283
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants