Android ConstraintLayout:带“的省略号文本;春天;?
我尝试从图片中实现布局。问题是TextView-我需要同时包装短文本和省略长文本,但无法实现这一点:Android ConstraintLayout:带“的省略号文本;春天;?,android,android-layout,android-constraintlayout,Android,Android Layout,Android Constraintlayout,我尝试从图片中实现布局。问题是TextView-我需要同时包装短文本和省略长文本,但无法实现这一点: layout\u width=“wrap\u content”-wrap是可以的,但当然不能省略(因为使用wrap\u content时没有应用任何约束) 布局\u width=“0dp”-包裹不起作用 layout\u width=“0dp”+constraintWidth\u default=“wrap”-wrap正常,ellipize不正常 还尝试玩constrainedWidth=“tr
layout\u width=“wrap\u content”
-wrap是可以的,但当然不能省略(因为使用wrap\u content时没有应用任何约束)布局\u width=“0dp”
-包裹不起作用layout\u width=“0dp”
+constraintWidth\u default=“wrap”
-wrap正常,ellipize不正常constrainedWidth=“true”
,但没有任何明显的效果
哦,成功了!我使用了类似问题的解决方案()-除非我将
按钮
从链中排除,并移除用作“弹簧”的空间,否则它不会有任何帮助。
这里是结果-工程完全如图所示
<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>
这里的图标是drawableEnd还是imageView?@Kartik imageView,这就是为什么我需要“包裹”行为,你可以拥有layout\u width=“包裹内容”
并在计算后以编程方式给出maxWidth
。通过这种方式,您可以实现这一点。@Kartik仅使用ConstraintLayout找到解决方案,如果您感兴趣,请参阅下面的答案