use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testMinHeight_initial_height_less_than_minHeight.
@Test
@FlakyTest
public void testMinHeight_initial_height_less_than_minHeight() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
// This test case verifies if the minHeight attribute works as a minimum constraint
// If the initial view height is less than the value of minHeight.
// The textView1's layout_height is set to wrap_content and its text is "1" apparently
// the initial measured height is less than the value of layout_minHeight (100dp)
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_minheight_test);
TextView textView1 = (TextView) activity.findViewById(R.id.text1);
int minHeight = ((FlexboxLayout.LayoutParams) textView1.getLayoutParams()).minHeight;
onView(withId(R.id.text1)).check(hasHeight(minHeight));
onView(withId(R.id.text2)).check(hasHeight(flexboxLayout.getHeight() - minHeight));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testAlignContent_center.
@Test
@FlakyTest
public void testAlignContent_center() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_align_content_test, new Configuration() {
@Override
public void apply(FlexboxLayout flexboxLayout) {
flexboxLayout.setAlignContent(FlexboxLayout.ALIGN_CONTENT_CENTER);
}
});
assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_CENTER));
onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
onView(withId(R.id.text3)).check(isBelow(withId(R.id.text1)));
TextView textView1 = (TextView) activity.findViewById(R.id.text1);
TextView textView3 = (TextView) activity.findViewById(R.id.text3);
int spaceAboveAndBottom = flexboxLayout.getHeight() - textView1.getHeight() - textView3.getHeight();
spaceAboveAndBottom /= 2;
assertThat(textView1.getTop(), isEqualAllowingError(spaceAboveAndBottom));
assertThat(flexboxLayout.getBottom() - textView3.getBottom(), isEqualAllowingError(spaceAboveAndBottom));
assertThat(flexboxLayout.getFlexLines().size(), is(2));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testAlignItems_center_wrapReverse.
@Test
@FlakyTest
public void testAlignItems_center_wrapReverse() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_align_items_test, new Configuration() {
@Override
public void apply(FlexboxLayout flexboxLayout) {
flexboxLayout.setFlexWrap(FlexboxLayout.FLEX_WRAP_WRAP_REVERSE);
flexboxLayout.setAlignItems(FlexboxLayout.ALIGN_ITEMS_CENTER);
}
});
assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_CENTER));
assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP_REVERSE));
onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
// There should be 2 flex lines in the layout with the given layout.
int flexLineSize = flexboxLayout.getHeight() / 2;
TextView textView1 = (TextView) activity.findViewById(R.id.text1);
TextView textView2 = (TextView) activity.findViewById(R.id.text2);
TextView textView3 = (TextView) activity.findViewById(R.id.text3);
// All TextView's heights are the same. No issues should be found if using the first
// TextView to calculate the space above and below
int spaceAboveAndBelow = (flexLineSize - textView1.getHeight()) / 2;
assertThat(textView1.getHeight(), not(flexLineSize));
assertThat(textView2.getHeight(), not(flexLineSize));
assertThat(textView3.getHeight(), not(flexLineSize));
assertThat(textView1.getBottom(), isEqualAllowingError(flexboxLayout.getHeight() - spaceAboveAndBelow));
assertThat(textView2.getBottom(), isEqualAllowingError(flexboxLayout.getHeight() - spaceAboveAndBelow));
assertThat(textView3.getBottom(), isEqualAllowingError(flexboxLayout.getHeight() - flexLineSize - spaceAboveAndBelow));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testChildBottomMarginIncluded_flexContainerWrapContent_directionColumn_flexShrink.
@Test
@FlakyTest
public void testChildBottomMarginIncluded_flexContainerWrapContent_directionColumn_flexShrink() throws Throwable {
// This test is to verify the case where:
// - layout_width is set to wrap_content for the FlexboxLayout
// - flex_wrap is set to nowrap for the FlexboxLayout
// - End (or start) margin is set to a child
// - The child which the has the end (start) margin has the largest width in the
// same flex line
// - The child has a positive layout_flexShrink attribute set
// - The sum of children height overflows parent's height (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_column_shrink);
// layout_width for text1: 24dp, layout_marginEnd: 12dp
assertThat(flexboxLayout.getWidth(), isEqualAllowingError(TestUtil.dpToPixel(mActivityRule.getActivity(), 36)));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testAlignItems_flexEnd_parentPadding_column.
@Test
@FlakyTest
public void testAlignItems_flexEnd_parentPadding_column() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_align_items_parent_padding_test, new Configuration() {
@Override
public void apply(FlexboxLayout flexboxLayout) {
flexboxLayout.setAlignItems(FlexboxLayout.ALIGN_ITEMS_FLEX_END);
flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
}
});
assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_FLEX_END));
assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
TextView textView1 = (TextView) activity.findViewById(R.id.text1);
TextView textView2 = (TextView) activity.findViewById(R.id.text2);
assertThat(textView1.getRight(), is(flexboxLayout.getRight() - flexboxLayout.getPaddingRight()));
assertThat(textView2.getRight(), is(flexboxLayout.getRight() - flexboxLayout.getPaddingRight()));
}
Aggregations