提交 d277195a 编写于 作者: T Takeshi Hagikura

Fixes the #47

Change-Id: I6951cb986e096276255374e5962084353471a2ee
上级 163d5714
......@@ -2583,6 +2583,64 @@ public class FlexboxAndroidTest {
assertThat(textView5.getTop(), is(textView3.getBottom()));
}
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testView_visibility_gone_first_item_in_flex_line_horizontal() throws Throwable {
// This test verifies if the FlexboxLayout is visible when the visibility of the first
// flex item in the second flex line (or arbitrary flex lines other than the first flex line)
// is set to "gone"
// There was an issue reported for that
// https://github.com/google/flexbox-layout/issues/47
final FlexboxTestActivity activity = mActivityRule.getActivity();
mActivityRule.runOnUiThread(new Runnable() {
@Override
public void run() {
activity.setContentView(
R.layout.activity_visibility_gone_first_item_in_flex_line_row);
}
});
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_ROW));
TextView textView1 = (TextView) activity.findViewById(R.id.text1);
TextView textView3 = (TextView) activity.findViewById(R.id.text3);
assertTrue(flexboxLayout.getHeight() > 0);
assertThat(flexboxLayout.getHeight(), is(textView1.getHeight() + textView3.getHeight()));
}
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testView_visibility_gone_first_item_in_flex_line_vertical() throws Throwable {
// This test verifies if the FlexboxLayout is visible when the visibility of the first
// flex item in the second flex line (or arbitrary flex lines other than the first flex line)
// is set to "gone"
// There was an issue reported for that
// https://github.com/google/flexbox-layout/issues/47
final FlexboxTestActivity activity = mActivityRule.getActivity();
mActivityRule.runOnUiThread(new Runnable() {
@Override
public void run() {
activity.setContentView(
R.layout.activity_visibility_gone_first_item_in_flex_line_column);
}
});
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
TextView textView1 = (TextView) activity.findViewById(R.id.text1);
TextView textView3 = (TextView) activity.findViewById(R.id.text3);
assertTrue(flexboxLayout.getWidth() > 0);
assertThat(flexboxLayout.getWidth(), is(textView1.getWidth() + textView3.getWidth()));
}
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testView_visibility_invisible() throws Throwable {
......
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2016 Google Inc. All rights reserved.
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.
-->
<com.google.android.flexbox.FlexboxLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/flexbox_layout"
android:layout_width="wrap_content"
android:layout_height="360dp"
app:flexDirection="column"
app:flexWrap="wrap">
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="160dp"
android:text="1" />
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="160dp"
android:text="2" />
<TextView
android:id="@+id/text3"
android:layout_width="wrap_content"
android:layout_height="160dp"
android:visibility="gone"
android:text="3" />
</com.google.android.flexbox.FlexboxLayout>
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2016 Google Inc. All rights reserved.
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.
-->
<com.google.android.flexbox.FlexboxLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/flexbox_layout"
android:layout_width="360dp"
android:layout_height="wrap_content"
app:flexDirection="row"
app:flexWrap="wrap">
<TextView
android:id="@+id/text1"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:text="1" />
<TextView
android:id="@+id/text2"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:text="2" />
<TextView
android:id="@+id/text3"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:visibility="gone"
android:text="3" />
</com.google.android.flexbox.FlexboxLayout>
......@@ -442,9 +442,11 @@ public class FlexboxLayout extends ViewGroup {
for (int i = 0; i < childCount; i++) {
View child = getReorderedChildAt(i);
if (child == null) {
addFlexLineIfLastFlexItem(i, childCount, paddingEnd, flexLine);
continue;
} else if (child.getVisibility() == View.GONE) {
flexLine.itemCount++;
addFlexLineIfLastFlexItem(i, childCount, paddingEnd, flexLine);
continue;
}
......@@ -519,11 +521,7 @@ public class FlexboxLayout extends ViewGroup {
child.getMeasuredHeight() - child.getBaseline()
+ lp.bottomMargin);
}
if (i == childCount - 1 && flexLine.itemCount != 0) {
// Add the flex line if this item is the last item
flexLine.mainSize += paddingEnd;
mFlexLines.add(flexLine);
}
addFlexLineIfLastFlexItem(i, childCount, paddingEnd, flexLine);
}
}
......@@ -595,9 +593,11 @@ public class FlexboxLayout extends ViewGroup {
for (int i = 0; i < childCount; i++) {
View child = getReorderedChildAt(i);
if (child == null) {
addFlexLineIfLastFlexItem(i, childCount, paddingBottom, flexLine);
continue;
} else if (child.getVisibility() == View.GONE) {
flexLine.itemCount++;
addFlexLineIfLastFlexItem(i, childCount, paddingBottom, flexLine);
continue;
}
......@@ -660,11 +660,7 @@ public class FlexboxLayout extends ViewGroup {
// later
flexLine.crossSize = Math.max(flexLine.crossSize, largestWidthInColumn);
if (i == childCount - 1 && flexLine.itemCount != 0) {
// Add the flex line if this item is the last item
flexLine.mainSize += paddingBottom;
mFlexLines.add(flexLine);
}
addFlexLineIfLastFlexItem(i, childCount, paddingBottom, flexLine);
}
determineMainSize(mFlexDirection, widthMeasureSpec, heightMeasureSpec);
......@@ -676,6 +672,15 @@ public class FlexboxLayout extends ViewGroup {
childState);
}
private void addFlexLineIfLastFlexItem(int childIndex, int childCount, int paddingToAdd,
FlexLine flexLine) {
if (childIndex == childCount - 1 && flexLine.itemCount != 0) {
// Add the flex line if this item is the last item
flexLine.mainSize += paddingToAdd;
mFlexLines.add(flexLine);
}
}
/**
* Determine the main size by expanding (shrinking if negative remaining free space is given)
* an individual child in each flex line if any children's flexGrow (or flexShrink if remaining
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册