gpt4 book ai didi

android - TextView 动态宽度与末尾的 View

转载 作者:行者123 更新时间:2023-12-05 00:11:07 35 4
gpt4 key购买 nike

我有两个元素,TextViewImageViewImageView 将位于 TextView 的末尾。 TextView 的宽度会根据文本改变,ImageView 也跟在 TextView 的末尾。像这样:

enter image description here

但问题是,如果文本太长,ImageView 会超出屏幕,如下所示:

enter image description here

但是应该是这样的:

enter image description here

我怎样才能只通过 XML 获得它?我知道它可以通过编程实现,但我想要一个 XML 解决方案。

注意:ImageView 可以是一个Button,所以我不能像解决方案那样使用drawableEnd

最佳答案

你可以试试这里的关键是 app:layout_constrainedWidth="true"

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="lefttttttttttttttttttttttttttttttttttttttttttttttttt"
app:layout_constrainedWidth="true"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/right"
app:layout_constraintTop_toTopOf="parent"/>
<ImageView
android:id="@+id/right"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@mipmap/ic_launcher"
app:layout_constraintStart_toEndOf="@id/left"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/left"
/>
</android.support.constraint.ConstraintLayout>

关于android - TextView 动态宽度与末尾的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59430019/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com