@@ -3777,6 +3777,78 @@ class FlexboxAndroidTest {
37773777 onView(withId(R .id.text3)).check(isTopAlignedWith(withId(R .id.flexbox_layout)))
37783778 }
37793779
3780+ @Test
3781+ @FlakyTest
3782+ @Throws(Throwable ::class )
3783+ fun testAddItemProgrammatically_withMarginLayoutParams () {
3784+ val activity = activityRule.activity
3785+ val flexboxLayout = createFlexboxLayout(R .layout.activity_empty_children,
3786+ object : Configuration {
3787+ override fun apply (flexboxLayout : FlexboxLayout ) {
3788+ flexboxLayout.alignItems = AlignItems .FLEX_START
3789+ val first = createTextView(activity, " 1" , 0 )
3790+ val second = createTextView(activity, " 2" , 0 )
3791+ val lp1 = ViewGroup .MarginLayoutParams (100 , 100 )
3792+ lp1.setMargins(10 , 10 , 10 , 10 )
3793+ val lp2 = ViewGroup .MarginLayoutParams (100 , 100 )
3794+ lp2.setMargins(20 , 20 , 20 , 20 )
3795+ first.layoutParams = lp1
3796+ second.layoutParams = lp2
3797+ flexboxLayout.addView(first)
3798+ flexboxLayout.addView(second)
3799+ }
3800+ })
3801+
3802+ assertThat(flexboxLayout.childCount, `is `(2 ))
3803+ val view1 = flexboxLayout.getChildAt(0 )
3804+ val view2 = flexboxLayout.getChildAt(1 )
3805+ // Assert the coordinates of the views added programmatically with margins
3806+ assertThat(view1.left, `is `(10 ))
3807+ assertThat(view1.top, `is `(10 ))
3808+ assertThat(view1.bottom, `is `(110 ))
3809+ assertThat(view1.right, `is `(110 ))
3810+ assertThat(view2.left, `is `(140 ))
3811+ assertThat(view2.top, `is `(20 ))
3812+ assertThat(view2.bottom, `is `(120 ))
3813+ assertThat(view2.right, `is `(240 ))
3814+ }
3815+
3816+ @Test
3817+ @FlakyTest
3818+ @Throws(Throwable ::class )
3819+ fun testAddItemProgrammatically_withFlexboxLayoutLayoutParams () {
3820+ val activity = activityRule.activity
3821+ val flexboxLayout = createFlexboxLayout(R .layout.activity_empty_children,
3822+ object : Configuration {
3823+ override fun apply (flexboxLayout : FlexboxLayout ) {
3824+ flexboxLayout.alignItems = AlignItems .FLEX_START
3825+ val first = createTextView(activity, " 1" , 0 )
3826+ val second = createTextView(activity, " 2" , 0 )
3827+ val lp1 = FlexboxLayout .LayoutParams (100 , 100 )
3828+ lp1.setMargins(10 , 10 , 10 , 10 )
3829+ val lp2 = FlexboxLayout .LayoutParams (100 , 100 )
3830+ lp2.setMargins(20 , 20 , 20 , 20 )
3831+ first.layoutParams = lp1
3832+ second.layoutParams = lp2
3833+ flexboxLayout.addView(first)
3834+ flexboxLayout.addView(second)
3835+ }
3836+ })
3837+
3838+ assertThat(flexboxLayout.childCount, `is `(2 ))
3839+ val view1 = flexboxLayout.getChildAt(0 )
3840+ val view2 = flexboxLayout.getChildAt(1 )
3841+ // Assert the coordinates of the views added programmatically with margins
3842+ assertThat(view1.left, `is `(10 ))
3843+ assertThat(view1.top, `is `(10 ))
3844+ assertThat(view1.bottom, `is `(110 ))
3845+ assertThat(view1.right, `is `(110 ))
3846+ assertThat(view2.left, `is `(140 ))
3847+ assertThat(view2.top, `is `(20 ))
3848+ assertThat(view2.bottom, `is `(120 ))
3849+ assertThat(view2.right, `is `(240 ))
3850+ }
3851+
37803852 @Throws(Throwable ::class )
37813853 private fun createFlexboxLayout (@LayoutRes activityLayoutResId : Int ,
37823854 configuration : Configuration = Configuration .EMPTY ): FlexboxLayout {
0 commit comments