use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testFlexDirection_column_alignItems_center_margin_oneSide.
@Test
@FlakyTest
public void testFlexDirection_column_alignItems_center_margin_oneSide() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_direction_column_align_items_center_margin_oneside);
assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN));
TextView text1 = (TextView) activity.findViewById(R.id.text1);
assertThat(text1.getLeft(), isEqualAllowingError(TestUtil.dpToPixel(activity, 30)));
assertThat(flexboxLayout.getRight() - text1.getRight(), isEqualAllowingError(TestUtil.dpToPixel(activity, 50)));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testOrderAttribute_removeLastView.
@Test
@FlakyTest
public void testOrderAttribute_removeLastView() throws Throwable {
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_order_test, new Configuration() {
@Override
public void apply(FlexboxLayout flexboxLayout) {
flexboxLayout.removeViewAt(flexboxLayout.getChildCount() - 1);
}
});
assertNotNull(flexboxLayout);
assertThat(flexboxLayout.getChildCount(), is(3));
// 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: 2, index 0
assertThat(((TextView) flexboxLayout.getReorderedChildAt(2)).getText().toString(), is(String.valueOf(1)));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testAlignContent_spaceAround.
@Test
@FlakyTest
public void testAlignContent_spaceAround() 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_SPACE_AROUND);
}
});
assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_SPACE_AROUND));
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)));
TextView textView1 = (TextView) activity.findViewById(R.id.text1);
TextView textView3 = (TextView) activity.findViewById(R.id.text3);
int spaceAround = flexboxLayout.getHeight() - textView1.getHeight() - textView3.getHeight();
// Divide by the number of flex lines * 2
spaceAround /= 4;
assertThat(textView1.getTop(), isEqualAllowingError(spaceAround));
int spaceInMiddle = textView1.getBottom() + spaceAround * 2;
assertThat(textView3.getTop(), isEqualAllowingError(spaceInMiddle));
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_flexDirection_column.
@Test
@FlakyTest
public void testAlignItems_center_wrapReverse_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.setFlexWrap(FlexboxLayout.FLEX_WRAP_WRAP_REVERSE);
flexboxLayout.setAlignItems(FlexboxLayout.ALIGN_ITEMS_CENTER);
flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
}
});
assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_CENTER));
assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP_REVERSE));
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)));
// There should be 2 flex lines in the layout with the given layout.
int flexLineSize = flexboxLayout.getWidth() / 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 widths are the same. No issues should be found if using the first
// TextView to calculate the space above and below
int spaceLeftAndRight = (flexLineSize - textView1.getWidth()) / 2;
assertThat(textView1.getWidth(), not(flexLineSize));
assertThat(textView2.getWidth(), not(flexLineSize));
assertThat(textView3.getWidth(), not(flexLineSize));
assertThat(textView1.getRight(), isEqualAllowingError(flexboxLayout.getWidth() - spaceLeftAndRight));
assertThat(textView2.getRight(), isEqualAllowingError(flexboxLayout.getWidth() - spaceLeftAndRight));
assertThat(textView3.getRight(), isEqualAllowingError(flexboxLayout.getWidth() - flexLineSize - spaceLeftAndRight));
}
use of com.google.android.flexbox.FlexboxLayout in project flexbox-layout by google.
the class FlexboxAndroidTest method testFlexItem_match_parent_flexDirection_column.
@Test
@FlakyTest
public void testFlexItem_match_parent_flexDirection_column() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
FlexboxLayout flexboxLayout = createFlexboxLayout(R.layout.activity_flex_item_match_parent_direction_column, new Configuration() {
@Override
public void apply(FlexboxLayout flexboxLayout) {
flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN);
}
});
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(text1.getHeight(), is(flexboxLayout.getHeight()));
assertThat(text2.getHeight(), is(flexboxLayout.getHeight()));
assertThat(text3.getHeight(), is(flexboxLayout.getHeight()));
assertThat(flexboxLayout.getWidth(), is(text1.getWidth() + text2.getWidth() + text3.getWidth()));
}
Aggregations