use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testAlignContent_spaceBetween_withPadding.
@Test
@FlakyTest
public void testAlignContent_spaceBetween_withPadding() throws Throwable {
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_align_content_test, new Configuration() {
@Override
public void apply(FlexboxLayout flexboxLayout) {
flexboxLayout.setAlignContent(FlexboxLayout.ALIGN_CONTENT_SPACE_BETWEEN);
}
});
assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_SPACE_BETWEEN));
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(isRightOf(withId(R.id.text1)));
onView(withId(R.id.text2)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text3)).check(isBottomAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testDivider_directionRow_all_thickDivider.
@Test
@FlakyTest
public void testDivider_directionRow_all_thickDivider() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_divider_test_direction_row, new Configuration() {
@Override
public void apply(FlexboxLayout flexboxLayout) {
Drawable thickDivider = ResourcesCompat.getDrawable(activity.getResources(), R.drawable.divider_thick, null);
flexboxLayout.setDividerDrawableVertical(thickDivider);
flexboxLayout.setShowDividerVertical(FlexboxLayout.SHOW_DIVIDER_BEGINNING | FlexboxLayout.SHOW_DIVIDER_MIDDLE | FlexboxLayout.SHOW_DIVIDER_END);
}
});
assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_ROW));
assertThat(flexboxLayout.getShowDividerVertical(), is(FlexboxLayout.SHOW_DIVIDER_BEGINNING | FlexboxLayout.SHOW_DIVIDER_MIDDLE | FlexboxLayout.SHOW_DIVIDER_END));
TextView text1 = (TextView) activity.findViewById(R.id.text1);
TextView text2 = (TextView) activity.findViewById(R.id.text2);
TextView text3 = (TextView) activity.findViewById(R.id.text3);
Drawable divider = ResourcesCompat.getDrawable(activity.getResources(), R.drawable.divider_thick, null);
// The sum of three text views and the sum of thick dividers don't fit in one line.
// The last text view should be placed to the next line.
assertNotNull(divider);
int widthSumFirstRow = text1.getWidth() + text2.getWidth() + divider.getIntrinsicWidth() * 3;
assertThat(text2.getRight() + divider.getIntrinsicWidth(), is(widthSumFirstRow));
assertThat(text1.getLeft(), is(not(flexboxLayout.getLeft())));
assertThat(text3.getBottom(), is(text1.getHeight() + text2.getHeight()));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testWrap_parentPadding_horizontal.
@Test
@FlakyTest
public void testWrap_parentPadding_horizontal() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_wrap_parent_padding_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
// parent padding, 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);
assertThat(flexboxLayout.getHeight(), is(flexboxLayout.getPaddingTop() + flexboxLayout.getPaddingBottom() + text1.getHeight() + text2.getHeight()));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testJustifyContent_center_withParentPadding.
@Test
@FlakyTest
public void testJustifyContent_center_withParentPadding() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_justify_content_with_parent_padding, new Configuration() {
@Override
public void apply(FlexboxLayout flexboxLayout) {
flexboxLayout.setJustifyContent(FlexboxLayout.JUSTIFY_CONTENT_CENTER);
}
});
assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_CENTER));
onView(withId(R.id.text2)).check(isRightOf(withId(R.id.text1)));
onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
TextView textView1 = (TextView) activity.findViewById(R.id.text1);
TextView textView2 = (TextView) activity.findViewById(R.id.text2);
TextView textView3 = (TextView) activity.findViewById(R.id.text3);
int space = flexboxLayout.getWidth() - textView1.getWidth() - textView2.getWidth() - textView3.getWidth() - flexboxLayout.getPaddingLeft() - flexboxLayout.getPaddingRight();
space = space / 2;
assertThat(textView1.getLeft() - flexboxLayout.getPaddingLeft(), isEqualAllowingError(space));
assertThat(flexboxLayout.getWidth() - textView3.getRight() - flexboxLayout.getPaddingRight(), isEqualAllowingError(space));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testMinWidth_initial_width_less_than_minWidth.
@Test
@FlakyTest
public void testMinWidth_initial_width_less_than_minWidth() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
// This test case verifies if the minWidth attribute works as a minimum constraint
// If the initial view width is less than the value of minWidth.
// The textView1's layout_width is set to wrap_content and its text is "1" apparently
// the initial measured width is less than the value of layout_minWidth (100dp)
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_minwidth_test);
TextView textView1 = (TextView) activity.findViewById(R.id.text1);
int minWidth = ((FlexboxLayout.LayoutParams) textView1.getLayoutParams()).minWidth;
onView(withId(R.id.text1)).check(hasWidth(minWidth));
onView(withId(R.id.text2)).check(hasWidth(flexboxLayout.getWidth() - minWidth));
}
Aggregations