【发布时间】:2018-03-04 03:26:41
【问题描述】:
问题 1:
虽然我在ConstraintLayout中使用guideline,但它根本不起作用,下面的代码无法设置guideline的orientation(为什么没有这样的属性?),这是没用的:
constraintLayout {
guideline {
//here, cannot set the orientation of guideline
}
//...
}
虽然下面的代码可以设置准线方向,但是布局还是有同样的问题(不知道是否创建了准线):
constraintLayout {
constraintSet {
create(ID_GUIDELINE, VERTICAL_GUIDELINE)
}
//...
}
那么,在 Anko 的 ConstraintLayout 布局中使用 GuideLines 的正确方法是什么?
问题 2:
另一个ConstraintLayout中的ConstraintLayou在使用Fragment时可能会出现意外行为。
我在Activity中使用ConstraintLayout(以A命名),在Fragment中使用ConstraintLayout(B),然后添加或替换B进入/与A,结果显示B的宽度总是不正确。
但是,如果B中有RecyclerView,则B的layoutParams设置如下:
layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)
那么它就可以正常工作了,没有RecyclerView而只有其他小部件,比如buttons/textviews/imageviews,这表明B的宽度很窄。
当然,我可以将布局 A 更改为 FrameLayout,但这不是我想要的,那么为什么以及如何做到这一点?谢谢回复!
另外,我在这里打开了 Anko kotlin 库中的问题:https://github.com/Kotlin/anko/issues/579,代码:
// A in Activity
constraintLayout {
fitsSystemWindows = true
id = A
}
supportFragmentManager.beginTransaction().replace(A, fragmentB).commit()
//supportFragmentManager.beginTransaction().add(A, fragmentB).commit()
// B in Fragment
constraintLayout {
fitsSystemWindows = true
layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)
}
【问题讨论】:
标签: android kotlin android-constraintlayout anko