提交 69c753eb 编写于 作者: T Takeshi Hagikura

Prevent an empty flex line is added when the first flex item's initial length

is large enough to be judged a line wrapping is required.

Change-Id: I2526d00fe53fccfbab5959a10f33d11dfa5f62fa
上级 620c9fe3
......@@ -3018,6 +3018,72 @@ public class FlexboxAndroidTest {
is(text1.getHeight() + text2.getHeight() + lp2.topMargin + lp2.bottomMargin));
}
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testFirstItemLarge_horizontal() throws Throwable {
// This test verifies a empty flex line is not added when the first flex item is large
// and judged wrapping is required with the first item.
final FlexboxTestActivity activity = mActivityRule.getActivity();
mActivityRule.runOnUiThread(new Runnable() {
@Override
public void run() {
activity.setContentView(R.layout.activity_first_item_large_horizontal_test);
}
});
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));
assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_STRETCH));
assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_STRETCH));
// The sum of width of TextView1 and TextView2 is not enough for wrapping, but considering
// the margin for the TextView2, the second TextView should be wrapped
onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text2)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text3)).check(isBottomAlignedWith(withId(R.id.flexbox_layout)));
TextView text1 = (TextView) activity.findViewById(R.id.text1);
TextView text2 = (TextView) activity.findViewById(R.id.text2);
TextView text3 = (TextView) activity.findViewById(R.id.text3);
assertThat(flexboxLayout.getHeight(),
is(text1.getHeight() + text2.getHeight() + text3.getHeight()));
}
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testFirstItemLarge_vertical() throws Throwable {
// This test verifies a empty flex line is not added when the first flex item is large
// and judged wrapping is required with the first item.
final FlexboxTestActivity activity = mActivityRule.getActivity();
mActivityRule.runOnUiThread(new Runnable() {
@Override
public void run() {
activity.setContentView(R.layout.activity_first_item_large_vertical_test);
}
});
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));
assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_STRETCH));
assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_STRETCH));
// The sum of width of TextView1 and TextView2 is not enough for wrapping, but considering
// the margin for the TextView2, the second TextView should be wrapped
onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text3)).check(isRightAlignedWith(withId(R.id.flexbox_layout)));
TextView text1 = (TextView) activity.findViewById(R.id.text1);
TextView text2 = (TextView) activity.findViewById(R.id.text2);
TextView text3 = (TextView) activity.findViewById(R.id.text3);
assertThat(flexboxLayout.getWidth(),
is(text1.getWidth() + text2.getWidth() + text3.getWidth()));
}
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testWrap_childMargin_vertical() 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="320dp"
android:layout_height="320dp"
app:flexDirection="row"
app:flexWrap="wrap"
app:alignItems="stretch"
app:alignContent="stretch">
<TextView
android:id="@+id/text1"
android:layout_width="500dp"
android:layout_height="60dp"
android:text="1" />
<TextView
android:id="@+id/text2"
android:layout_width="120dp"
android:layout_height="60dp"
android:text="2" />
<TextView
android:id="@+id/text3"
android:layout_width="300dp"
android:layout_height="60dp"
android:text="3" />
</com.google.android.flexbox.FlexboxLayout>
\ No newline at end of file
<?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="320dp"
android:layout_height="320dp"
app:flexDirection="column"
app:flexWrap="wrap"
app:alignItems="stretch"
app:alignContent="stretch">
<TextView
android:id="@+id/text1"
android:layout_width="60dp"
android:layout_height="500dp"
android:text="1" />
<TextView
android:id="@+id/text2"
android:layout_width="60dp"
android:layout_height="120dp"
android:text="2" />
<TextView
android:id="@+id/text3"
android:layout_width="6dp"
android:layout_height="300dp"
android:text="3" />
</com.google.android.flexbox.FlexboxLayout>
\ No newline at end of file
......@@ -499,7 +499,9 @@ public class FlexboxLayout extends ViewGroup {
if (isWrapRequired(mFlexWrap, widthMode, widthSize, flexLine.mainSize,
child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin, lp)) {
mFlexLines.add(flexLine);
if (flexLine.itemCount > 0) {
mFlexLines.add(flexLine);
}
flexLine = new FlexLine();
flexLine.itemCount = 1;
......@@ -650,7 +652,9 @@ public class FlexboxLayout extends ViewGroup {
if (isWrapRequired(mFlexWrap, heightMode, heightSize, flexLine.mainSize,
child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin, lp)) {
mFlexLines.add(flexLine);
if (flexLine.itemCount > 0) {
mFlexLines.add(flexLine);
}
flexLine = new FlexLine();
flexLine.itemCount = 1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册