use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testFlexWrap_nowrap_flexDirection_column.
@Test
@FlakyTest
public void testFlexWrap_nowrap_flexDirection_column() throws Throwable {
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_flex_wrap_test, new Configuration() {
@Override
public void apply(FlexboxLayout flexboxLayout) {
flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
flexboxLayout.setFlexWrap(FlexboxLayout.FLEX_WRAP_NOWRAP);
}
});
assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_NOWRAP));
assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
onView(withId(R.id.text2)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
// The height of the FlexboxLayout is not enough for placing the three text views.
// But the flexWrap attribute is set to FLEX_WRAP_NOWRAP, the third text view is placed
// below the second one and overflowing the parent FlexboxLayout.
onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
assertThat(flexboxLayout.getFlexLines().size(), is(1));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testChildBottomMarginIncluded_flexContainerWrapContent_directionRow_flexShrink.
@Test
@FlakyTest
public void testChildBottomMarginIncluded_flexContainerWrapContent_directionRow_flexShrink() throws Throwable {
// This test is to verify the case where:
// - layout_height is set to wrap_content for the FlexboxLayout
// - flex_wrap is set to nowrap for the FlexboxLayout
// - Bottom (or top) margin is set to a child
// - The child which the has the bottom (top) margin has the largest height in the
// same flex line
// - The child has a positive layout_flexShrink attribute set
// - The sum of children width overflows parent's width (shrink will happen)
// If these conditions were met, the height of the FlexboxLayout didn't take the bottom
// margin on the child into account
// See https://github.com/google/flexbox-layout/issues/154
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_wrap_content_child_bottom_margin_row_shrink);
// layout_height for text1: 24dp, layout_marginBottom: 12dp
assertThat(flexboxLayout.getHeight(), isEqualAllowingError(TestUtil.dpToPixel(mActivityRule.getActivity(), 36)));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testJustifyContent_spaceAround_including_gone_views.
@Test
@FlakyTest
public void testJustifyContent_spaceAround_including_gone_views() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_justify_content_with_gone, new Configuration() {
@Override
public void apply(FlexboxLayout flexboxLayout) {
flexboxLayout.setJustifyContent(FlexboxLayout.JUSTIFY_CONTENT_SPACE_AROUND);
}
});
assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_SPACE_AROUND));
TextView textView1 = (TextView) activity.findViewById(R.id.text1);
TextView textView3 = (TextView) activity.findViewById(R.id.text3);
int space = flexboxLayout.getWidth() - textView1.getWidth() - textView3.getWidth();
// Divide by the number of visible children * 2
space = space / 4;
assertThat(textView1.getLeft(), isEqualAllowingError(space));
int spaceInMiddle = space * 2;
assertThat(textView3.getLeft() - textView1.getRight(), isEqualAllowingError(spaceInMiddle));
assertThat(flexboxLayout.getRight() - textView3.getRight(), isEqualAllowingError(space));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testWrap_parentPadding_vertical.
@Test
@FlakyTest
public void testWrap_parentPadding_vertical() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_wrap_parent_padding_vertical_test);
assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
// The sum of height of TextView1 and TextView2 is not enough for wrapping, but considering
// parent padding, the second TextView should be wrapped
onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
TextView text1 = (TextView) activity.findViewById(R.id.text1);
TextView text2 = (TextView) activity.findViewById(R.id.text2);
assertThat(flexboxLayout.getWidth(), is(flexboxLayout.getPaddingLeft() + flexboxLayout.getPaddingRight() + text1.getWidth() + text2.getWidth()));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testWrap_childMargin_horizontal.
@Test
@FlakyTest
public void testWrap_childMargin_horizontal() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_wrap_child_margin_horizontal_test);
assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_ROW));
// 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.text2)).check(isBelow(withId(R.id.text1)));
onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
TextView text1 = (TextView) activity.findViewById(R.id.text1);
TextView text2 = (TextView) activity.findViewById(R.id.text2);
FlexboxLayout.LayoutParams lp2 = (FlexboxLayout.LayoutParams) text2.getLayoutParams();
assertThat(flexboxLayout.getHeight(), is(text1.getHeight() + text2.getHeight() + lp2.topMargin + lp2.bottomMargin));
}
Aggregations