Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
门心叼龙
flexbox-layout
提交
3fd14340
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 搜索 >>
提交
3fd14340
编写于
9月 25, 2017
作者:
T
Takeshi Hagikura
提交者:
GitHub
9月 25, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix the issue that margins for items added programmatically were not taken into account. (#359)
上级
d1994f5a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
80 addition
and
3 deletion
+80
-3
demo-playground/src/main/java/com/google/android/flexbox/FlexboxLayoutFragment.kt
.../java/com/google/android/flexbox/FlexboxLayoutFragment.kt
+1
-1
flexbox/src/androidTest/java/com/google/android/flexbox/test/FlexboxAndroidTest.kt
...ava/com/google/android/flexbox/test/FlexboxAndroidTest.kt
+72
-0
flexbox/src/main/java/com/google/android/flexbox/FlexboxLayout.java
...c/main/java/com/google/android/flexbox/FlexboxLayout.java
+7
-2
未找到文件。
demo-playground/src/main/java/com/google/android/flexbox/FlexboxLayoutFragment.kt
浏览文件 @
3fd14340
...
...
@@ -57,7 +57,7 @@ class FlexboxLayoutFragment : Fragment() {
flexContainer
.
addView
(
textView
)
}
}
else
{
for
(
i
in
0
..
flexContainer
.
flexItemCount
-
1
)
{
for
(
i
in
0
until
flexContainer
.
flexItemCount
)
{
flexContainer
.
getFlexItemAt
(
i
).
setOnClickListener
(
FlexItemClickListener
(
activity
,
FlexItemChangedListenerImpl
(
flexContainer
),
i
))
...
...
flexbox/src/androidTest/java/com/google/android/flexbox/test/FlexboxAndroidTest.kt
浏览文件 @
3fd14340
...
...
@@ -3777,6 +3777,78 @@ class FlexboxAndroidTest {
onView
(
withId
(
R
.
id
.
text3
)).
check
(
isTopAlignedWith
(
withId
(
R
.
id
.
flexbox_layout
)))
}
@Test
@FlakyTest
@Throws
(
Throwable
::
class
)
fun
testAddItemProgrammatically_withMarginLayoutParams
()
{
val
activity
=
activityRule
.
activity
val
flexboxLayout
=
createFlexboxLayout
(
R
.
layout
.
activity_empty_children
,
object
:
Configuration
{
override
fun
apply
(
flexboxLayout
:
FlexboxLayout
)
{
flexboxLayout
.
alignItems
=
AlignItems
.
FLEX_START
val
first
=
createTextView
(
activity
,
"1"
,
0
)
val
second
=
createTextView
(
activity
,
"2"
,
0
)
val
lp1
=
ViewGroup
.
MarginLayoutParams
(
100
,
100
)
lp1
.
setMargins
(
10
,
10
,
10
,
10
)
val
lp2
=
ViewGroup
.
MarginLayoutParams
(
100
,
100
)
lp2
.
setMargins
(
20
,
20
,
20
,
20
)
first
.
layoutParams
=
lp1
second
.
layoutParams
=
lp2
flexboxLayout
.
addView
(
first
)
flexboxLayout
.
addView
(
second
)
}
})
assertThat
(
flexboxLayout
.
childCount
,
`is`
(
2
))
val
view1
=
flexboxLayout
.
getChildAt
(
0
)
val
view2
=
flexboxLayout
.
getChildAt
(
1
)
// Assert the coordinates of the views added programmatically with margins
assertThat
(
view1
.
left
,
`is`
(
10
))
assertThat
(
view1
.
top
,
`is`
(
10
))
assertThat
(
view1
.
bottom
,
`is`
(
110
))
assertThat
(
view1
.
right
,
`is`
(
110
))
assertThat
(
view2
.
left
,
`is`
(
140
))
assertThat
(
view2
.
top
,
`is`
(
20
))
assertThat
(
view2
.
bottom
,
`is`
(
120
))
assertThat
(
view2
.
right
,
`is`
(
240
))
}
@Test
@FlakyTest
@Throws
(
Throwable
::
class
)
fun
testAddItemProgrammatically_withFlexboxLayoutLayoutParams
()
{
val
activity
=
activityRule
.
activity
val
flexboxLayout
=
createFlexboxLayout
(
R
.
layout
.
activity_empty_children
,
object
:
Configuration
{
override
fun
apply
(
flexboxLayout
:
FlexboxLayout
)
{
flexboxLayout
.
alignItems
=
AlignItems
.
FLEX_START
val
first
=
createTextView
(
activity
,
"1"
,
0
)
val
second
=
createTextView
(
activity
,
"2"
,
0
)
val
lp1
=
FlexboxLayout
.
LayoutParams
(
100
,
100
)
lp1
.
setMargins
(
10
,
10
,
10
,
10
)
val
lp2
=
FlexboxLayout
.
LayoutParams
(
100
,
100
)
lp2
.
setMargins
(
20
,
20
,
20
,
20
)
first
.
layoutParams
=
lp1
second
.
layoutParams
=
lp2
flexboxLayout
.
addView
(
first
)
flexboxLayout
.
addView
(
second
)
}
})
assertThat
(
flexboxLayout
.
childCount
,
`is`
(
2
))
val
view1
=
flexboxLayout
.
getChildAt
(
0
)
val
view2
=
flexboxLayout
.
getChildAt
(
1
)
// Assert the coordinates of the views added programmatically with margins
assertThat
(
view1
.
left
,
`is`
(
10
))
assertThat
(
view1
.
top
,
`is`
(
10
))
assertThat
(
view1
.
bottom
,
`is`
(
110
))
assertThat
(
view1
.
right
,
`is`
(
110
))
assertThat
(
view2
.
left
,
`is`
(
140
))
assertThat
(
view2
.
top
,
`is`
(
20
))
assertThat
(
view2
.
bottom
,
`is`
(
120
))
assertThat
(
view2
.
right
,
`is`
(
240
))
}
@Throws
(
Throwable
::
class
)
private
fun
createFlexboxLayout
(
@LayoutRes
activityLayoutResId
:
Int
,
configuration
:
Configuration
=
Configuration
.
EMPTY
):
FlexboxLayout
{
...
...
flexbox/src/main/java/com/google/android/flexbox/FlexboxLayout.java
浏览文件 @
3fd14340
...
...
@@ -1106,8 +1106,13 @@ public class FlexboxLayout extends ViewGroup implements FlexContainer {
}
@Override
protected
ViewGroup
.
LayoutParams
generateLayoutParams
(
ViewGroup
.
LayoutParams
p
)
{
return
new
LayoutParams
(
p
);
protected
ViewGroup
.
LayoutParams
generateLayoutParams
(
ViewGroup
.
LayoutParams
lp
)
{
if
(
lp
instanceof
FlexboxLayout
.
LayoutParams
)
{
return
new
FlexboxLayout
.
LayoutParams
((
FlexboxLayout
.
LayoutParams
)
lp
);
}
else
if
(
lp
instanceof
MarginLayoutParams
)
{
return
new
FlexboxLayout
.
LayoutParams
((
MarginLayoutParams
)
lp
);
}
return
new
LayoutParams
(
lp
);
}
@FlexDirection
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录