如何在使用ConstraintLayout中的链式布局(packed chain style)时防止出现双重边框

huangapple 未分类评论53阅读模式
英文:

How to prevent double border when using packed chain style in ConstraintLayout

问题

我正在使用水平链与紧凑风格在一个拥有许多TextView的约束布局中(它们之间没有边距),所有的TextView都有一个带状矩形边框,结果是每个相邻的一对都有**“双倍”**边框。不幸的是,ConstraintLayout不支持负边距。我花了两天多的时间来编写所有的代码。请告诉我如何修复它(防止宽边框)?任何帮助都将不胜感激。

如何在使用ConstraintLayout中的链式布局(packed chain style)时防止出现双重边框

英文:

I'm using horizontal chain with packed style in a constraint layout that has a lot of TextView's (without a margin between them), all TextView's have a drawable rectangle border, and as a result each consecutive pairs have "double" border. Unfortunately, ConstraintLayout doesn't support negative margin. It took me more then two days to write all code. Please tell me how can i fix it (prevent a wide border)?
Any help will be blessed.
如何在使用ConstraintLayout中的链式布局(packed chain style)时防止出现双重边框

答案1

得分: 0

我找到了一个解决方案(虽然不是最好的,但我希望它能满足)...
我们可以在循环中(当索引 i 递增一次)遍历所有该行上的 TextView,并使用函数 setTrananaltionX,并将减去 i(例如 -i)作为参数。建议在使用 setTranslationX 方法时将索引 i 转换为 DP 单位。
当我们完成对所有 TextView 运行的遍历后,我们将在链中的第一项上使用 setHorizontalBias 方法,其参数大于 0.5(我使用了 0.55),这样“紧凑”链条将返回到相反的方向(与我们在使用 setTranslation 方法时“前进的方向相反”)。

英文:

I Found a solution (not the best one, but i hope it's satisfy)..
We can run in a loop (when index i incremented by one) over all the TextView's on the line and use the function setTrananaltionX with minus i (e.g -i) as an argument. I suggest converting index i to DP units when using setTranslationX method.
When we have finished running on all the TextView's, we will use setHorizontalBias method on the first item at the chain, with an argument that is bigger than 0.5 (i used 0.55) so the "packed" chain will go back to opposite direction (the opposite direction from the direction it "went toward when we have used setTranslation method)

huangapple
  • 本文由 发表于 2020年4月6日 03:40:24
  • 转载请务必保留本文链接:https://java.coder-hub.com/61048442.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定