Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
门心叼龙
flexbox-layout
提交
3aa56093
F
flexbox-layout
项目概览
门心叼龙
/
flexbox-layout
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
flexbox-layout
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
3aa56093
编写于
2月 14, 2018
作者:
T
Takeshi Hagikura
提交者:
GitHub
2月 14, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement space_evenly as one of the values for Justify Content. (#404)
Implement space_evenly as one of the values for Justify Content.
上级
cd4c6352
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
327 addition
and
8 deletion
+327
-8
demo-playground/src/main/java/com/google/android/flexbox/FragmentHelper.kt
...rc/main/java/com/google/android/flexbox/FragmentHelper.kt
+5
-0
demo-playground/src/main/res/values/strings.xml
demo-playground/src/main/res/values/strings.xml
+2
-0
flexbox/src/androidTest/java/com/google/android/flexbox/test/FlexboxAndroidTest.kt
...ava/com/google/android/flexbox/test/FlexboxAndroidTest.kt
+118
-0
flexbox/src/androidTest/java/com/google/android/flexbox/test/FlexboxLayoutManagerTest.kt
...m/google/android/flexbox/test/FlexboxLayoutManagerTest.kt
+143
-0
flexbox/src/main/java/com/google/android/flexbox/FlexboxLayout.java
...c/main/java/com/google/android/flexbox/FlexboxLayout.java
+32
-8
flexbox/src/main/java/com/google/android/flexbox/FlexboxLayoutManager.java
...java/com/google/android/flexbox/FlexboxLayoutManager.java
+16
-0
flexbox/src/main/java/com/google/android/flexbox/JustifyContent.java
.../main/java/com/google/android/flexbox/JustifyContent.java
+10
-0
flexbox/src/main/res/values/attrs.xml
flexbox/src/main/res/values/attrs.xml
+1
-0
未找到文件。
demo-playground/src/main/java/com/google/android/flexbox/FragmentHelper.kt
浏览文件 @
3aa56093
...
...
@@ -61,6 +61,8 @@ internal class FragmentHelper(private val activity: MainActivity, private val fl
private
lateinit
var
SPACE_AROUND
:
String
private
lateinit
var
SPACE_EVENLY
:
String
private
lateinit
var
sharedPreferences
:
SharedPreferences
fun
initializeViews
()
{
...
...
@@ -91,6 +93,7 @@ internal class FragmentHelper(private val activity: MainActivity, private val fl
STRETCH
=
activity
.
getString
(
R
.
string
.
stretch
)
SPACE_BETWEEN
=
activity
.
getString
(
R
.
string
.
space_between
)
SPACE_AROUND
=
activity
.
getString
(
R
.
string
.
space_around
)
SPACE_EVENLY
=
activity
.
getString
(
R
.
string
.
space_evenly
)
}
/**
...
...
@@ -224,6 +227,7 @@ internal class FragmentHelper(private val activity: MainActivity, private val fl
CENTER
->
JustifyContent
.
CENTER
SPACE_BETWEEN
->
JustifyContent
.
SPACE_BETWEEN
SPACE_AROUND
->
JustifyContent
.
SPACE_AROUND
SPACE_EVENLY
->
JustifyContent
.
SPACE_EVENLY
else
->
return
}
}
...
...
@@ -239,6 +243,7 @@ internal class FragmentHelper(private val activity: MainActivity, private val fl
JustifyContent
.
CENTER
->
CENTER
JustifyContent
.
SPACE_AROUND
->
SPACE_AROUND
JustifyContent
.
SPACE_BETWEEN
->
SPACE_BETWEEN
JustifyContent
.
SPACE_EVENLY
->
SPACE_EVENLY
else
->
FLEX_START
}
}
...
...
demo-playground/src/main/res/values/strings.xml
浏览文件 @
3aa56093
...
...
@@ -42,6 +42,7 @@ limitations under the License.
<string
name=
"center"
translatable=
"false"
>
Center
</string>
<string
name=
"space_between"
translatable=
"false"
>
Space Between
</string>
<string
name=
"space_around"
translatable=
"false"
>
Space Around
</string>
<string
name=
"space_evenly"
translatable=
"false"
>
Space Evenly
</string>
<string
name=
"baseline"
translatable=
"false"
>
Baseline
</string>
<string
name=
"stretch"
translatable=
"false"
>
Stretch
</string>
<string
name=
"auto"
translatable=
"false"
>
Auto
</string>
...
...
@@ -65,6 +66,7 @@ limitations under the License.
<item>
@string/center
</item>
<item>
@string/space_between
</item>
<item>
@string/space_around
</item>
<item>
@string/space_evenly
</item>
</string-array>
<string-array
translatable=
"false"
name=
"array_align_items"
>
...
...
flexbox/src/androidTest/java/com/google/android/flexbox/test/FlexboxAndroidTest.kt
浏览文件 @
3aa56093
...
...
@@ -716,6 +716,34 @@ class FlexboxAndroidTest {
assertThat
(
flexboxLayout
.
right
-
textView3
.
right
,
isEqualAllowingError
(
space
))
}
@Test
@FlakyTest
@Throws
(
Throwable
::
class
)
fun
testJustifyContent_spaceEvenly
()
{
val
activity
=
activityRule
.
activity
val
flexboxLayout
=
createFlexboxLayout
(
R
.
layout
.
activity_justify_content_test
,
object
:
Configuration
{
override
fun
apply
(
flexboxLayout
:
FlexboxLayout
)
{
flexboxLayout
.
justifyContent
=
JustifyContent
.
SPACE_EVENLY
}
})
assertThat
(
flexboxLayout
.
justifyContent
,
`is`
(
JustifyContent
.
SPACE_EVENLY
))
onView
(
withId
(
R
.
id
.
text1
)).
check
(
isTopAlignedWith
(
withId
(
R
.
id
.
flexbox_layout
)))
onView
(
withId
(
R
.
id
.
text2
)).
check
(
isTopAlignedWith
(
withId
(
R
.
id
.
flexbox_layout
)))
onView
(
withId
(
R
.
id
.
text3
)).
check
(
isTopAlignedWith
(
withId
(
R
.
id
.
flexbox_layout
)))
val
textView1
=
activity
.
findViewById
<
TextView
>(
R
.
id
.
text1
)
val
textView2
=
activity
.
findViewById
<
TextView
>(
R
.
id
.
text2
)
val
textView3
=
activity
.
findViewById
<
TextView
>(
R
.
id
.
text3
)
var
space
=
flexboxLayout
.
width
-
textView1
.
width
-
textView2
.
width
-
textView3
.
width
space
/=
4
// Divide by the number of children + 1
assertThat
(
textView1
.
left
,
isEqualAllowingError
(
space
))
assertThat
(
textView2
.
left
-
textView1
.
right
,
isEqualAllowingError
(
space
))
assertThat
(
textView3
.
left
-
textView2
.
right
,
isEqualAllowingError
(
space
))
assertThat
(
flexboxLayout
.
right
-
textView3
.
right
,
isEqualAllowingError
(
space
))
}
@Test
@FlakyTest
@Throws
(
Throwable
::
class
)
...
...
@@ -746,6 +774,35 @@ class FlexboxAndroidTest {
assertThat
(
flexboxLayout
.
right
-
textView3
.
right
-
padding
,
isEqualAllowingError
(
space
))
}
@Test
@FlakyTest
@Throws
(
Throwable
::
class
)
fun
testJustifyContent_spaceEvenly_withPadding
()
{
val
activity
=
activityRule
.
activity
val
padding
=
40
val
flexboxLayout
=
createFlexboxLayout
(
R
.
layout
.
activity_justify_content_test
,
object
:
Configuration
{
override
fun
apply
(
flexboxLayout
:
FlexboxLayout
)
{
flexboxLayout
.
justifyContent
=
JustifyContent
.
SPACE_EVENLY
flexboxLayout
.
setPadding
(
padding
,
padding
,
padding
,
padding
)
}
})
assertThat
(
flexboxLayout
.
justifyContent
,
`is`
(
JustifyContent
.
SPACE_EVENLY
))
val
textView1
=
activity
.
findViewById
<
TextView
>(
R
.
id
.
text1
)
val
textView2
=
activity
.
findViewById
<
TextView
>(
R
.
id
.
text2
)
val
textView3
=
activity
.
findViewById
<
TextView
>(
R
.
id
.
text3
)
var
space
=
flexboxLayout
.
width
-
textView1
.
width
-
textView2
.
width
-
textView3
.
width
-
padding
*
2
space
/=
4
// Divide by the number of children + 1
assertThat
(
textView1
.
left
-
padding
,
isEqualAllowingError
(
space
))
assertThat
(
textView2
.
left
-
textView1
.
right
,
isEqualAllowingError
(
space
))
assertThat
(
textView3
.
left
-
textView2
.
right
,
isEqualAllowingError
(
space
))
assertThat
(
flexboxLayout
.
right
-
textView3
.
right
-
padding
,
isEqualAllowingError
(
space
))
}
@Test
@FlakyTest
@Throws
(
Throwable
::
class
)
...
...
@@ -907,6 +964,36 @@ class FlexboxAndroidTest {
assertThat
(
flexboxLayout
.
bottom
-
textView3
.
bottom
,
isEqualAllowingError
(
space
))
}
@Test
@FlakyTest
@Throws
(
Throwable
::
class
)
fun
testJustifyContent_spaceEvenly_flexDirection_column
()
{
val
activity
=
activityRule
.
activity
val
flexboxLayout
=
createFlexboxLayout
(
R
.
layout
.
activity_justify_content_test
,
object
:
Configuration
{
override
fun
apply
(
flexboxLayout
:
FlexboxLayout
)
{
flexboxLayout
.
justifyContent
=
JustifyContent
.
SPACE_EVENLY
flexboxLayout
.
flexDirection
=
FlexDirection
.
COLUMN
}
})
assertThat
(
flexboxLayout
.
justifyContent
,
`is`
(
JustifyContent
.
SPACE_EVENLY
))
assertThat
(
flexboxLayout
.
flexDirection
,
`is`
(
FlexDirection
.
COLUMN
))
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
.
text3
)).
check
(
isLeftAlignedWith
(
withId
(
R
.
id
.
flexbox_layout
)))
val
textView1
=
activity
.
findViewById
<
TextView
>(
R
.
id
.
text1
)
val
textView2
=
activity
.
findViewById
<
TextView
>(
R
.
id
.
text2
)
val
textView3
=
activity
.
findViewById
<
TextView
>(
R
.
id
.
text3
)
var
space
=
flexboxLayout
.
height
-
textView1
.
height
-
textView2
.
height
-
textView3
.
height
space
/=
4
// Divide by the number of children + 1
assertThat
(
textView1
.
top
,
isEqualAllowingError
(
space
))
assertThat
(
textView2
.
top
-
textView1
.
bottom
,
isEqualAllowingError
(
space
))
assertThat
(
textView3
.
top
-
textView2
.
bottom
,
isEqualAllowingError
(
space
))
assertThat
(
flexboxLayout
.
bottom
-
textView3
.
bottom
,
isEqualAllowingError
(
space
))
}
@Test
@FlakyTest
@Throws
(
Throwable
::
class
)
...
...
@@ -938,6 +1025,37 @@ class FlexboxAndroidTest {
assertThat
(
flexboxLayout
.
bottom
-
textView3
.
bottom
-
padding
,
isEqualAllowingError
(
space
))
}
@Test
@FlakyTest
@Throws
(
Throwable
::
class
)
fun
testJustifyContent_spaceEvenly_flexDirection_column_withPadding
()
{
val
activity
=
activityRule
.
activity
val
padding
=
40
val
flexboxLayout
=
createFlexboxLayout
(
R
.
layout
.
activity_justify_content_test
,
object
:
Configuration
{
override
fun
apply
(
flexboxLayout
:
FlexboxLayout
)
{
flexboxLayout
.
justifyContent
=
JustifyContent
.
SPACE_EVENLY
flexboxLayout
.
flexDirection
=
FlexDirection
.
COLUMN
flexboxLayout
.
setPadding
(
padding
,
padding
,
padding
,
padding
)
}
})
assertThat
(
flexboxLayout
.
justifyContent
,
`is`
(
JustifyContent
.
SPACE_EVENLY
))
assertThat
(
flexboxLayout
.
flexDirection
,
`is`
(
FlexDirection
.
COLUMN
))
val
textView1
=
activity
.
findViewById
<
TextView
>(
R
.
id
.
text1
)
val
textView2
=
activity
.
findViewById
<
TextView
>(
R
.
id
.
text2
)
val
textView3
=
activity
.
findViewById
<
TextView
>(
R
.
id
.
text3
)
var
space
=
flexboxLayout
.
height
-
textView1
.
height
-
textView2
.
height
-
textView3
.
height
-
padding
*
2
space
/=
4
// Divide by the number of children + 1
assertThat
(
textView1
.
top
-
padding
,
isEqualAllowingError
(
space
))
assertThat
(
textView2
.
top
-
textView1
.
bottom
,
isEqualAllowingError
(
space
))
assertThat
(
textView3
.
top
-
textView2
.
bottom
,
isEqualAllowingError
(
space
))
assertThat
(
flexboxLayout
.
bottom
-
textView3
.
bottom
-
padding
,
isEqualAllowingError
(
space
))
}
@Test
@FlakyTest
@Throws
(
Throwable
::
class
)
...
...
flexbox/src/androidTest/java/com/google/android/flexbox/test/FlexboxLayoutManagerTest.kt
浏览文件 @
3aa56093
...
...
@@ -479,6 +479,41 @@ class FlexboxLayoutManagerTest {
assertThat
(
layoutManager
.
getChildAt
(
2
).
right
,
isEqualAllowingError
(
activity
.
dpToPixel
(
292
)))
}
@Test
@FlakyTest
@Throws
(
Throwable
::
class
)
fun
testJustifyContent_spaceEvenly_direction_row
()
{
val
activity
=
activityRule
.
activity
val
layoutManager
=
FlexboxLayoutManager
(
activity
)
val
adapter
=
TestAdapter
()
activityRule
.
runOnUiThread
{
activity
.
setContentView
(
R
.
layout
.
recyclerview
)
val
recyclerView
=
activity
.
findViewById
<
RecyclerView
>(
R
.
id
.
recyclerview
)
recyclerView
.
layoutManager
=
layoutManager
recyclerView
.
adapter
=
adapter
val
lp1
=
createLayoutParams
(
activity
,
50
,
100
)
adapter
.
addItem
(
lp1
)
val
lp2
=
createLayoutParams
(
activity
,
50
,
100
)
adapter
.
addItem
(
lp2
)
val
lp3
=
createLayoutParams
(
activity
,
50
,
100
)
adapter
.
addItem
(
lp3
)
layoutManager
.
justifyContent
=
JustifyContent
.
SPACE_EVENLY
// RecyclerView width: 320, height: 240.
}
InstrumentationRegistry
.
getInstrumentation
().
waitForIdleSync
()
assertThat
(
layoutManager
.
justifyContent
,
`is`
(
JustifyContent
.
SPACE_EVENLY
))
assertThat
(
layoutManager
.
flexItemCount
,
`is`
(
3
))
assertThat
(
layoutManager
.
flexLines
.
size
,
`is`
(
1
))
assertThat
(
layoutManager
.
getChildAt
(
0
).
left
,
isEqualAllowingError
(
activity
.
dpToPixel
(
43
)))
assertThat
(
layoutManager
.
getChildAt
(
0
).
right
,
isEqualAllowingError
(
activity
.
dpToPixel
(
93
)))
assertThat
(
layoutManager
.
getChildAt
(
1
).
left
,
isEqualAllowingError
(
activity
.
dpToPixel
(
135
)))
assertThat
(
layoutManager
.
getChildAt
(
1
).
right
,
isEqualAllowingError
(
activity
.
dpToPixel
(
185
)))
assertThat
(
layoutManager
.
getChildAt
(
2
).
left
,
isEqualAllowingError
(
activity
.
dpToPixel
(
228
)))
assertThat
(
layoutManager
.
getChildAt
(
2
).
right
,
isEqualAllowingError
(
activity
.
dpToPixel
(
278
)))
}
@Test
@FlakyTest
@Throws
(
Throwable
::
class
)
...
...
@@ -657,6 +692,42 @@ class FlexboxLayoutManagerTest {
assertThat
(
layoutManager
.
getChildAt
(
2
).
right
,
isEqualAllowingError
(
activity
.
dpToPixel
(
78
)))
}
@Test
@FlakyTest
@Throws
(
Throwable
::
class
)
fun
testJustifyContent_spaceEvenly_direction_rowReverse
()
{
val
activity
=
activityRule
.
activity
val
layoutManager
=
FlexboxLayoutManager
(
activity
)
val
adapter
=
TestAdapter
()
activityRule
.
runOnUiThread
{
activity
.
setContentView
(
R
.
layout
.
recyclerview
)
val
recyclerView
=
activity
.
findViewById
<
RecyclerView
>(
R
.
id
.
recyclerview
)
recyclerView
.
layoutManager
=
layoutManager
recyclerView
.
adapter
=
adapter
val
lp1
=
createLayoutParams
(
activity
,
50
,
100
)
adapter
.
addItem
(
lp1
)
val
lp2
=
createLayoutParams
(
activity
,
50
,
100
)
adapter
.
addItem
(
lp2
)
val
lp3
=
createLayoutParams
(
activity
,
50
,
100
)
adapter
.
addItem
(
lp3
)
layoutManager
.
flexDirection
=
FlexDirection
.
ROW_REVERSE
layoutManager
.
justifyContent
=
JustifyContent
.
SPACE_EVENLY
// RecyclerView width: 320, height: 240.
}
InstrumentationRegistry
.
getInstrumentation
().
waitForIdleSync
()
assertThat
(
layoutManager
.
flexDirection
,
`is`
(
FlexDirection
.
ROW_REVERSE
))
assertThat
(
layoutManager
.
justifyContent
,
`is`
(
JustifyContent
.
SPACE_EVENLY
))
assertThat
(
layoutManager
.
flexItemCount
,
`is`
(
3
))
assertThat
(
layoutManager
.
flexLines
.
size
,
`is`
(
1
))
assertThat
(
layoutManager
.
getChildAt
(
0
).
left
,
isEqualAllowingError
(
activity
.
dpToPixel
(
228
)))
assertThat
(
layoutManager
.
getChildAt
(
0
).
right
,
isEqualAllowingError
(
activity
.
dpToPixel
(
278
)))
assertThat
(
layoutManager
.
getChildAt
(
1
).
left
,
isEqualAllowingError
(
activity
.
dpToPixel
(
135
)))
assertThat
(
layoutManager
.
getChildAt
(
1
).
right
,
isEqualAllowingError
(
activity
.
dpToPixel
(
185
)))
assertThat
(
layoutManager
.
getChildAt
(
2
).
left
,
isEqualAllowingError
(
activity
.
dpToPixel
(
43
)))
assertThat
(
layoutManager
.
getChildAt
(
2
).
right
,
isEqualAllowingError
(
activity
.
dpToPixel
(
93
)))
}
@Test
@FlakyTest
@Throws
(
Throwable
::
class
)
...
...
@@ -837,6 +908,42 @@ class FlexboxLayoutManagerTest {
assertThat
(
layoutManager
.
getChildAt
(
2
).
bottom
,
isEqualAllowingError
(
activity
.
dpToPixel
(
225
)))
}
@Test
@FlakyTest
@Throws
(
Throwable
::
class
)
fun
testJustifyContent_spaceEvenly_direction_column
()
{
val
activity
=
activityRule
.
activity
val
layoutManager
=
FlexboxLayoutManager
(
activity
)
val
adapter
=
TestAdapter
()
activityRule
.
runOnUiThread
{
activity
.
setContentView
(
R
.
layout
.
recyclerview
)
val
recyclerView
=
activity
.
findViewById
<
RecyclerView
>(
R
.
id
.
recyclerview
)
recyclerView
.
layoutManager
=
layoutManager
recyclerView
.
adapter
=
adapter
val
lp1
=
createLayoutParams
(
activity
,
100
,
50
)
adapter
.
addItem
(
lp1
)
val
lp2
=
createLayoutParams
(
activity
,
100
,
50
)
adapter
.
addItem
(
lp2
)
val
lp3
=
createLayoutParams
(
activity
,
100
,
50
)
adapter
.
addItem
(
lp3
)
layoutManager
.
flexDirection
=
FlexDirection
.
COLUMN
layoutManager
.
justifyContent
=
JustifyContent
.
SPACE_EVENLY
// RecyclerView width: 320, height: 240.
}
InstrumentationRegistry
.
getInstrumentation
().
waitForIdleSync
()
assertThat
(
layoutManager
.
flexDirection
,
`is`
(
FlexDirection
.
COLUMN
))
assertThat
(
layoutManager
.
justifyContent
,
`is`
(
JustifyContent
.
SPACE_EVENLY
))
assertThat
(
layoutManager
.
flexItemCount
,
`is`
(
3
))
assertThat
(
layoutManager
.
flexLines
.
size
,
`is`
(
1
))
assertThat
(
layoutManager
.
getChildAt
(
0
).
top
,
isEqualAllowingError
(
activity
.
dpToPixel
(
23
)))
assertThat
(
layoutManager
.
getChildAt
(
0
).
bottom
,
isEqualAllowingError
(
activity
.
dpToPixel
(
73
)))
assertThat
(
layoutManager
.
getChildAt
(
1
).
top
,
isEqualAllowingError
(
activity
.
dpToPixel
(
95
)))
assertThat
(
layoutManager
.
getChildAt
(
1
).
bottom
,
isEqualAllowingError
(
activity
.
dpToPixel
(
145
)))
assertThat
(
layoutManager
.
getChildAt
(
2
).
top
,
isEqualAllowingError
(
activity
.
dpToPixel
(
167
)))
assertThat
(
layoutManager
.
getChildAt
(
2
).
bottom
,
isEqualAllowingError
(
activity
.
dpToPixel
(
217
)))
}
@Test
@FlakyTest
@Throws
(
Throwable
::
class
)
...
...
@@ -1017,6 +1124,42 @@ class FlexboxLayoutManagerTest {
assertThat
(
layoutManager
.
getChildAt
(
2
).
bottom
,
isEqualAllowingError
(
activity
.
dpToPixel
(
65
)))
}
@Test
@FlakyTest
@Throws
(
Throwable
::
class
)
fun
testJustifyContent_spaceEvenly_direction_columnReverse
()
{
val
activity
=
activityRule
.
activity
val
layoutManager
=
FlexboxLayoutManager
(
activity
)
val
adapter
=
TestAdapter
()
activityRule
.
runOnUiThread
{
activity
.
setContentView
(
R
.
layout
.
recyclerview
)
val
recyclerView
=
activity
.
findViewById
<
RecyclerView
>(
R
.
id
.
recyclerview
)
recyclerView
.
layoutManager
=
layoutManager
recyclerView
.
adapter
=
adapter
val
lp1
=
createLayoutParams
(
activity
,
100
,
50
)
adapter
.
addItem
(
lp1
)
val
lp2
=
createLayoutParams
(
activity
,
100
,
50
)
adapter
.
addItem
(
lp2
)
val
lp3
=
createLayoutParams
(
activity
,
100
,
50
)
adapter
.
addItem
(
lp3
)
layoutManager
.
flexDirection
=
FlexDirection
.
COLUMN_REVERSE
layoutManager
.
justifyContent
=
JustifyContent
.
SPACE_EVENLY
// RecyclerView width: 320, height: 240.
}
InstrumentationRegistry
.
getInstrumentation
().
waitForIdleSync
()
assertThat
(
layoutManager
.
flexDirection
,
`is`
(
FlexDirection
.
COLUMN_REVERSE
))
assertThat
(
layoutManager
.
justifyContent
,
`is`
(
JustifyContent
.
SPACE_EVENLY
))
assertThat
(
layoutManager
.
flexItemCount
,
`is`
(
3
))
assertThat
(
layoutManager
.
flexLines
.
size
,
`is`
(
1
))
assertThat
(
layoutManager
.
getChildAt
(
0
).
top
,
isEqualAllowingError
(
activity
.
dpToPixel
(
167
)))
assertThat
(
layoutManager
.
getChildAt
(
0
).
bottom
,
isEqualAllowingError
(
activity
.
dpToPixel
(
217
)))
assertThat
(
layoutManager
.
getChildAt
(
1
).
top
,
isEqualAllowingError
(
activity
.
dpToPixel
(
95
)))
assertThat
(
layoutManager
.
getChildAt
(
1
).
bottom
,
isEqualAllowingError
(
activity
.
dpToPixel
(
145
)))
assertThat
(
layoutManager
.
getChildAt
(
2
).
top
,
isEqualAllowingError
(
activity
.
dpToPixel
(
23
)))
assertThat
(
layoutManager
.
getChildAt
(
2
).
bottom
,
isEqualAllowingError
(
activity
.
dpToPixel
(
73
)))
}
@Test
@FlakyTest
@Throws
(
Throwable
::
class
)
...
...
flexbox/src/main/java/com/google/android/flexbox/FlexboxLayout.java
浏览文件 @
3aa56093
...
...
@@ -641,7 +641,7 @@ public class FlexboxLayout extends ViewGroup implements FlexContainer {
childLeft
=
paddingLeft
+
(
width
-
flexLine
.
mMainSize
)
/
2
f
;
childRight
=
width
-
paddingRight
-
(
width
-
flexLine
.
mMainSize
)
/
2
f
;
break
;
case
JustifyContent
.
SPACE_AROUND
:
case
JustifyContent
.
SPACE_AROUND
:
{
int
visibleCount
=
flexLine
.
getItemCountNotGone
();
if
(
visibleCount
!=
0
)
{
spaceBetweenItem
=
(
width
-
flexLine
.
mMainSize
)
...
...
@@ -650,13 +650,25 @@ public class FlexboxLayout extends ViewGroup implements FlexContainer {
childLeft
=
paddingLeft
+
spaceBetweenItem
/
2
f
;
childRight
=
width
-
paddingRight
-
spaceBetweenItem
/
2
f
;
break
;
case
JustifyContent
.
SPACE_BETWEEN
:
}
case
JustifyContent
.
SPACE_BETWEEN
:
{
childLeft
=
paddingLeft
;
int
visible
Item
=
flexLine
.
getItemCountNotGone
();
float
denominator
=
visible
Item
!=
1
?
visibleItem
-
1
:
1
f
;
int
visible
Count
=
flexLine
.
getItemCountNotGone
();
float
denominator
=
visible
Count
!=
1
?
visibleCount
-
1
:
1
f
;
spaceBetweenItem
=
(
width
-
flexLine
.
mMainSize
)
/
denominator
;
childRight
=
width
-
paddingRight
;
break
;
}
case
JustifyContent
.
SPACE_EVENLY
:
{
int
visibleCount
=
flexLine
.
getItemCountNotGone
();
if
(
visibleCount
!=
0
)
{
spaceBetweenItem
=
(
width
-
flexLine
.
mMainSize
)
/
(
float
)
(
visibleCount
+
1
);
}
childLeft
=
paddingLeft
+
spaceBetweenItem
;
childRight
=
width
-
paddingRight
-
spaceBetweenItem
;
break
;
}
default
:
throw
new
IllegalStateException
(
"Invalid justifyContent is set: "
+
mJustifyContent
);
...
...
@@ -786,7 +798,7 @@ public class FlexboxLayout extends ViewGroup implements FlexContainer {
childTop
=
paddingTop
+
(
height
-
flexLine
.
mMainSize
)
/
2
f
;
childBottom
=
height
-
paddingBottom
-
(
height
-
flexLine
.
mMainSize
)
/
2
f
;
break
;
case
JustifyContent
.
SPACE_AROUND
:
case
JustifyContent
.
SPACE_AROUND
:
{
int
visibleCount
=
flexLine
.
getItemCountNotGone
();
if
(
visibleCount
!=
0
)
{
spaceBetweenItem
=
(
height
-
flexLine
.
mMainSize
)
...
...
@@ -795,13 +807,25 @@ public class FlexboxLayout extends ViewGroup implements FlexContainer {
childTop
=
paddingTop
+
spaceBetweenItem
/
2
f
;
childBottom
=
height
-
paddingBottom
-
spaceBetweenItem
/
2
f
;
break
;
case
JustifyContent
.
SPACE_BETWEEN
:
}
case
JustifyContent
.
SPACE_BETWEEN
:
{
childTop
=
paddingTop
;
int
visible
Item
=
flexLine
.
getItemCountNotGone
();
float
denominator
=
visible
Item
!=
1
?
visibleItem
-
1
:
1
f
;
int
visible
Count
=
flexLine
.
getItemCountNotGone
();
float
denominator
=
visible
Count
!=
1
?
visibleCount
-
1
:
1
f
;
spaceBetweenItem
=
(
height
-
flexLine
.
mMainSize
)
/
denominator
;
childBottom
=
height
-
paddingBottom
;
break
;
}
case
JustifyContent
.
SPACE_EVENLY
:
{
int
visibleCount
=
flexLine
.
getItemCountNotGone
();
if
(
visibleCount
!=
0
)
{
spaceBetweenItem
=
(
height
-
flexLine
.
mMainSize
)
/
(
float
)
(
visibleCount
+
1
);
}
childTop
=
paddingTop
+
spaceBetweenItem
;
childBottom
=
height
-
paddingBottom
-
spaceBetweenItem
;
break
;
}
default
:
throw
new
IllegalStateException
(
"Invalid justifyContent is set: "
+
mJustifyContent
);
...
...
flexbox/src/main/java/com/google/android/flexbox/FlexboxLayoutManager.java
浏览文件 @
3aa56093
...
...
@@ -1469,6 +1469,14 @@ public class FlexboxLayoutManager extends RecyclerView.LayoutManager implements
spaceBetweenItem
=
(
parentWidth
-
flexLine
.
mMainSize
)
/
denominator
;
childRight
=
parentWidth
-
paddingRight
;
break
;
case
JustifyContent
.
SPACE_EVENLY
:
if
(
flexLine
.
mItemCount
!=
0
)
{
spaceBetweenItem
=
(
parentWidth
-
flexLine
.
mMainSize
)
/
(
float
)
(
flexLine
.
mItemCount
+
1
);
}
childLeft
=
paddingLeft
+
spaceBetweenItem
;
childRight
=
parentWidth
-
paddingRight
-
spaceBetweenItem
;
break
;
default
:
throw
new
IllegalStateException
(
"Invalid justifyContent is set: "
+
mJustifyContent
);
...
...
@@ -1580,6 +1588,14 @@ public class FlexboxLayoutManager extends RecyclerView.LayoutManager implements
spaceBetweenItem
=
(
parentHeight
-
flexLine
.
mMainSize
)
/
denominator
;
childBottom
=
parentHeight
-
paddingBottom
;
break
;
case
JustifyContent
.
SPACE_EVENLY
:
if
(
flexLine
.
mItemCount
!=
0
)
{
spaceBetweenItem
=
(
parentHeight
-
flexLine
.
mMainSize
)
/
(
float
)
(
flexLine
.
mItemCount
+
1
);
}
childTop
=
paddingTop
+
spaceBetweenItem
;
childBottom
=
parentHeight
-
paddingBottom
-
spaceBetweenItem
;
break
;
default
:
throw
new
IllegalStateException
(
"Invalid justifyContent is set: "
+
mJustifyContent
);
...
...
flexbox/src/main/java/com/google/android/flexbox/JustifyContent.java
浏览文件 @
3aa56093
...
...
@@ -47,4 +47,14 @@ public @interface JustifyContent {
* the flex lines.
*/
int
SPACE_AROUND
=
4
;
/**
* Flex items are evenly distributed along the flex line. The difference between
* {@link #SPACE_AROUND} is that all the spaces between items should be the same as the
* space before the first item and after the last item.
* See
* <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content">the document on MDN</a>
* for more details.
*/
int
SPACE_EVENLY
=
5
;
}
flexbox/src/main/res/values/attrs.xml
浏览文件 @
3aa56093
...
...
@@ -40,6 +40,7 @@ limitations under the License.
<enum
name=
"center"
value=
"2"
/>
<enum
name=
"space_between"
value=
"3"
/>
<enum
name=
"space_around"
value=
"4"
/>
<enum
name=
"space_evenly"
value=
"5"
/>
</attr>
<attr
name=
"alignItems"
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录