[英]How to use GuideLine in ConstraintLayout with Kotlin Anko layout
Question 1: 问题1:
While I use guideline
in ConstraintLayout, it doesn't work at all, the code below cannot set the orientation
(Why there is no such property?) of guideline
, which is useless: 虽然我用的
guideline
在ConstraintLayout,它不会在所有的工作,下面的代码无法设置orientation
(为什么没有这样的属性?)的guideline
,这是无用的:
constraintLayout {
guideline {
//here, cannot set the orientation of guideline
}
//...
}
Even though the code below can set the guideline orientation, but it still has the same problem with the layout(I don't know whether the guideline is created or not): 尽管下面的代码可以设置准则的方向,但是布局仍然存在相同的问题(我不知道准则是否已创建):
constraintLayout {
constraintSet {
create(ID_GUIDELINE, VERTICAL_GUIDELINE)
}
//...
}
So, what is the right way to use GuideLines in ConstraintLayout layout in Anko? 那么,在Anko的ConstraintLayout布局中使用GuideLines的正确方法是什么?
Question 2: 问题2:
ConstraintLayou in another ConstraintLayout may have the unexpected behavior while use Fragment
. 使用
Fragment
,另一个ConstraintLayout中的ConstraintLayou可能具有意外行为。
I use ConstraintLayout(named with A ) in Activity
, and ConstraintLayout( B ) in Fragment
, then add or replace the B into/with A , the result shows the width of B is always incorrect. 我在
Activity
使用ConstraintLayout(以A命名),在Fragment
ConstraintLayout( B ),然后将B添加或替换为A ,结果显示B的宽度始终不正确。
However, if there is a RecyclerView
in B , and set the layoutParams
of B as below: 然而,如果有一个
RecyclerView
在B,并设置layoutParams
B的如下:
layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)
then it works correctly, without RecyclerView
but only other widgets, like buttons/textviews/imageviews
, it shows that the width of B is very narrow. 然后它可以正常工作,没有
RecyclerView
,只有其他小部件,例如buttons/textviews/imageviews
,它表明B的宽度非常窄。
Of course I can change the layout A to a FrameLayout
, but that is not what I want, so why and how to do that? 当然,我可以将布局A更改为
FrameLayout
,但这不是我想要的,所以为什么以及如何做到这一点? Thanks for reply! 谢谢您的回复!
Also, I have opened the issue in Anko kotlin library here: https://github.com/Kotlin/anko/issues/579 , and code: 另外,我还在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)
}
Question 1 try something like this: 问题1尝试这样的事情:
guideline {
id = ID_GUIDELINE
}.lparams(0, 0) {
orientation = ConstraintLayout.LayoutParams.VERTICAL
guideBegin = dip(80)
}
Question 2 should be in a separate post with a good title so it's more likely to be answered and is more easily searchable by others. 问题2应该放在标题合适的单独帖子中,这样它更有可能被回答并且更容易被他人搜索。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.