use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testAlignItems_flexEnd.
@Test
@FlakyTest
public void testAlignItems_flexEnd() 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.setAlignItems(FlexboxLayout.ALIGN_ITEMS_FLEX_END);
}
});
assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_FLEX_END));
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)));
onView(withId(R.id.text3)).check(isBelow(withId(R.id.text1)));
onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
onView(withId(R.id.text3)).check(isBottomAlignedWith(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);
assertThat(textView1.getHeight(), not(flexLineSize));
assertThat(textView2.getHeight(), not(flexLineSize));
assertThat(textView3.getHeight(), not(flexLineSize));
assertThat(textView1.getBottom(), isEqualAllowingError(flexLineSize));
assertThat(textView2.getBottom(), isEqualAllowingError(flexLineSize));
assertThat(textView3.getBottom(), is(flexboxLayout.getBottom()));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testOrderAttribute_fromLayoutXml.
@Test
@FlakyTest
public void testOrderAttribute_fromLayoutXml() throws Throwable {
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_order_test);
assertNotNull(flexboxLayout);
assertThat(flexboxLayout.getChildCount(), is(4));
// order: -1, index 1
assertThat(((TextView) flexboxLayout.getReorderedChildAt(0)).getText().toString(), is(String.valueOf(2)));
// order: 0, index 2
assertThat(((TextView) flexboxLayout.getReorderedChildAt(1)).getText().toString(), is(String.valueOf(3)));
// order: 1, index 3
assertThat(((TextView) flexboxLayout.getReorderedChildAt(2)).getText().toString(), is(String.valueOf(4)));
// order: 2, index 0
assertThat(((TextView) flexboxLayout.getReorderedChildAt(3)).getText().toString(), is(String.valueOf(1)));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testAlignItems_flexEnd_flexDirection_column.
@Test
@FlakyTest
public void testAlignItems_flexEnd_flexDirection_column() 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.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.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text1)));
onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
onView(withId(R.id.text3)).check(isRightAlignedWith(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);
assertThat(textView1.getWidth(), not(flexLineSize));
assertThat(textView2.getWidth(), not(flexLineSize));
assertThat(textView3.getWidth(), not(flexLineSize));
assertThat(textView1.getRight(), isEqualAllowingError(flexLineSize));
assertThat(textView2.getRight(), isEqualAllowingError(flexLineSize));
assertThat(textView3.getRight(), is(flexboxLayout.getRight()));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testFlexBasisPercent_nowrap_flexDirection_column.
@Test
@FlakyTest
public void testFlexBasisPercent_nowrap_flexDirection_column() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_flex_basis_percent_test, new Configuration() {
@Override
public void apply(FlexboxLayout flexboxLayout) {
flexboxLayout.setFlexWrap(FlexboxLayout.FLEX_WRAP_NOWRAP);
flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
}
});
// The text1 length is 50%, the text2 length is 60% and the text3 has the fixed height,
// but the flex wrap attribute is FLEX_WRAP_NOWRAP, and flexShrink attributes for all
// children are the default value (1), three text views are shrank to fit in a single
// flex line.
assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_NOWRAP));
assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
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.text2)).check(isBelow(withId(R.id.text1)));
onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text3)).check(isBelow(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 totalHeight = textView1.getHeight() + textView2.getHeight() + textView3.getHeight();
// Allowing minor different length with the flex container since the sum of the three text
// views width is not always the same as the flex container's main size caused by round
// errors in calculating the percent lengths.
assertThat(flexboxLayout.getHeight(), isEqualAllowingError(totalHeight));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testEmptyChildren.
@Test
@FlakyTest
public void testEmptyChildren() throws Throwable {
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_empty_children);
assertThat(flexboxLayout.getChildCount(), is(0));
}
Aggregations