如何解决ConstraintLayout:带有“ spring”的椭圆形文字?
我尝试根据图片实现布局。问题是TextView-我需要同时包装短文本和ellipsize长文本,但是无法实现:
-
layout_width="wrap_content"
-自动换行是可以的,但是ellipsize当然不可以(因为当使用wrap_content时,因为没有施加约束) -
layout_width="0dp"
-包装无效 -
layout_width="0dp"
+constraintWidth_default="wrap"
-可以换行,不可以使用椭圆尺寸
也尝试过玩constrainedWidth="true"
,但是没有任何可见的效果。
解决方法
哦,做到了!我曾使用解决方案来解决类似的问题(ConstraintLayout Chains and Text Ellipsis + Image on the Right)-直到我从链中排除了Button
并删除了我用作“弹簧”的Space
!
这是结果-与图片完全相同。
<ConstraintLayout
android:layout_width="match_parent"
...>
<TextView
android:id="@+id/text"
android:layout_width="0dp" // enable constraints
android:ellipsize="end"
android:lines="1"
app:layout_constraintHorizontal_chainStyle="packed" // keep text + icon side by side
app:layout_constraintHorizontal_bias="0" // move text + icon to the left
app:layout_constraintWidth_default="wrap" // make text as small to wrap text
app:layout_constraintLeft_toLeftOf="parent" // chain starts
app:layout_constraintRight_toLeftOf="@id/icon" // chain continues
.../>
<ImageView
android:id="@+id/icon"
app:layout_constraintLeft_toRightOf="@id/text" // chain continues
app:layout_constraintRight_toLeftOf="@id/button" // chain ENDS!
.../>
<Button
android:id="@+id/button"
app:layout_constraintRight_toRightOf="parent" // move button to the right
// PAY ATTENTION! There is no constraintLeft_toRightOf="icon" attribute!
// because button must be out of chain
.../>
</ConstraintLayout>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。