android - 在 ConstraintLayout 中自动调整 TextView

标签 android textview android-constraintlayout

我在 ConstraintLayout 中有一条链子其中包含 TextView , 一个 ImageView和另一个 TextView (不需要自动调整大小)。我希望他们三个在父容器中垂直居中(即到左/右的距离相同)。

我想要 TextView自动调整大小,使文本不会溢出。我不能将 autosize 与 layout_width 一起使用设置为 wrap_content (没有任何 react ,文本不会调整大小)。我无法设置固定 layout_width要么因为文本不是很长时的额外空间会导致对齐。

无论如何可以通过 XML 执行此操作,还是我应该实现自己的自动调整大小行为?

这是我要实现的目标的图片(居中对齐的链):

最佳答案

对于 TextView 自动调整大小,请使用 android:layout_width="0dp" .

但请确保应用 ViewComponents Left/Start 和 Right/End 约束。

这个技巧基本上是用来代替android:layout_width="fill_parent"在约束布局中。

使用它,您将实现自动调整大小,它只会占用指定约束下的空间,并且不会重叠和溢出。

关于android - 在 ConstraintLayout 中自动调整 TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49802138/

相关文章:

c# - Unity 中的移动世界比例?

android - 我的 AndroidManifest.xml 有什么问题?语法错误?

Android的SoundPool不播放任何声音

android - 使用getSegment逐步绘制路径

android - Textview 根据屏幕宽度的百分比居中对齐

android - 使用 android :singleLine and android:autoLink 时按钮文本不可见

android - 自动调整 TextView 的大小不适合更新的文本

shadow - ConstraintLayout 中带有标高和阴影的 View

android - 对 ConstraintLayout 中的 LayoutParams 更改进行动画处理

android - 约束 View 内的 ListView 被剪切并且不滚动