ConstraintLayout 不会省略 TextView 中的长文本

2024-01-07

我有一个TextView在图像的右侧。我试图在图像旁边放置一些长文本,但该文本应通过在末尾添加“...”自动结束。然而,这是行不通的。我使用这个布局:

<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"
    android:layout_marginBottom="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="8dp">

<ImageView
    android:id="@+id/file_icon"
    android:layout_width="250px"
    android:layout_height="250px"
    android:layout_gravity="center"
    android:clickable="true"
    android:scaleType="centerInside"
    android:src="@drawable/ic_launcher"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/file_title"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:ellipsize="end"
    android:maxLines="1"
    android:text="This is a very long title and I hope I have the dots to break it"
    android:textAppearance="@style/TextAppearance.AppCompat.Medium"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toTopOf="@+id/file_type"
    app:layout_constraintVertical_chainStyle="packed"
    app:layout_constraintStart_toEndOf="@+id/file_icon"
    app:layout_constraintWidth_default="wrap"/>

<TextView
    android:id="@+id/file_type"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:text="Type"
    android:textAppearance="@style/TextAppearance.AppCompat.Small"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/file_title"
    app:layout_constraintLeft_toRightOf="@+id/file_icon" />

<ImageView
    android:id="@+id/file_download"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_gravity="center"
    android:clickable="true"
    android:scaleType="centerInside"
    android:src="@drawable/ic_action_download"
    app:layout_constraintTop_toBottomOf="@+id/file_title"
    app:layout_constraintRight_toRightOf="parent" />

结果是这样的:

为什么长文本没有省略,以致“...”出现在末尾?我读过了this https://stackoverflow.com/questions/45983394/android-constraintlayout-ellipsize-end-for-large-text and this https://stackoverflow.com/questions/40410786/constraintlayout-chains-and-text-ellipsis-image-on-the-right/43414504发布,但它对我不起作用。有人能帮我一下吗?


Use app:layout_constraintEnd_toEndOf="parent"给你的file_title TextView

Try this

<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"
    android:layout_marginBottom="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="8dp">

    <ImageView
        android:id="@+id/file_icon"
        android:layout_width="250px"
        android:layout_height="250px"
        android:layout_gravity="center"
        android:clickable="true"
        android:scaleType="centerInside"
        android:src="@drawable/abc"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/file_title"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:maxLines="1"
        android:text="This is a very long title and I hope I have the dots to break it"
        android:textAppearance="@style/TextAppearance.AppCompat.Medium"
        app:layout_constraintBottom_toTopOf="@+id/file_type"
        app:layout_constraintStart_toEndOf="@+id/file_icon"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_chainStyle="packed"
        app:layout_constraintEnd_toEndOf="parent"

        />

    <TextView
        android:id="@+id/file_type"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:text="Type"
        android:textAppearance="@style/TextAppearance.AppCompat.Small"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/file_icon"
        app:layout_constraintTop_toBottomOf="@+id/file_title" />

    <ImageView
        android:id="@+id/file_download"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_gravity="center"
        android:clickable="true"
        android:scaleType="centerInside"
        android:src="@drawable/abc"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/file_title" />

</android.support.constraint.ConstraintLayout>

OUTPUT

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ConstraintLayout 不会省略 TextView 中的长文本 的相关文章

  • 更改首选项的背景颜色

    我有一个PreferenceCategory xml 文件 我已经在其中定义了所有首选项 我从扩展的类中调用它PreferenceActivity 我无法设置设置屏幕的背景 该屏幕是在如下所示的 xml 文件的帮助下显示的 请看我已经定义了
  • 服务在后台运行?

    我正在构建的应用程序的功能之一是记录功能 我通过在服务中启动 MediaRecorder 对象来实现此目的 Intent intent new Intent v getContext RecordService class Messenge
  • 为网络和/或持久存储序列化 Android Bundle?

    我需要序列化一个全面的应用程序 游戏 状态 以便通过网络传输或保存到磁盘并在以后检索 当然 捆绑包用于在多个用例中保存 恢复状态 因此使用它们将是理想的选择 但是 由于某种原因 Bundle 不可序列化 寻找解决方案只发现了将 Bundle
  • Android 上的硬币识别

    我目前正在开发一个 Android 应用程序 它能够拍摄硬币的现有图像 或者使用内置摄像头扫描单个硬币 非常像 Google Goggles 我正在使用 Android 版 OpenCV 我的问题如下 什么方法最适合使用 OpenCV 在
  • Android,语言文件不起作用

    我现在正在创建一个 Android 应用程序 并尝试为我的母语添加语言文件 但在某种程度上 这对我不起作用 我尝试在两部不同的手机中加载该应用程序 但结果相同 之前创建过语言文件 效果良好 但这次不行 手机设置为瑞典语 语言文件适用于我创建
  • 将寻呼机视为列表视图行项目

    我有一个包含 20 行的列表视图 我想为列表视图中的每一行设置一个视图寻呼机 由于列表视图的行中的项目可能是一个或多个 并且我想使用视图分页器显示列表视图行项目 为此 我使用以下代码 将显示在列表视图行中的自定义布局 作为分页器项目
  • 从Asynctask返回结果

    如果我的 Android 应用程序中有这个后台工作文件 并且它从我的数据库获取数据 我如何将字符串 结果 传递给另一个类 后台工作人员连接到我的服务器 然后使用 php 连接到数据库 public class BackgroundWorke
  • 使用 POST 将数据从 Android 发送到 AppEngine Datastore

    抱歉 如果这是一个简单的问题 但我只是不知道我应该做什么 而且我认为我有点超出了我的深度 我想将数据从 Android 应用程序发送到在 Google App Engine 上运行的应用程序 数据必须从那里写入数据存储区 我的数据主要采用对
  • android studio 底部工具栏的“运行”选项卡消失了

    Android Studio 底部工具栏中曾经有一个 运行 选项卡 但该选项卡不再显示 怎么把它带回来 请检查下图以了解它消失之前的位置 Run 选项卡曾经位于 TODO 选项卡之前的红色圆圈中 查看 gt 工具窗口 gt 运行 Or us
  • 用于代码生成的 ANTLR 工具版本 4.7.1 与当前运行时版本 4.5.3 不匹配

    我正在开发一个 Android 应用程序 当前使用 DSL 和一些库 突然构建给了我这个错误 任务 app kaptDebugKotlin 失败 用于代码生成的 ANTLR 工具版本 4 7 1 与当前运行时版本 4 5 3 不匹配 用于解
  • 如何知道点击的widget id?

    我已经实施了一个widget与ImageButton and a TextView That ImageButton启动一个activity当它被点击时 这activity使用用户在活动上写入的内容更新小部件文本EditText 现在的问题
  • MAT(Eclipse 内存分析器)- 如何从内存转储中查看位图

    I m analyzing memory usage of my Android app with help of Eclipse Memory Analyzer http www eclipse org mat also known as
  • Android - 内容值覆盖现有行

    我正在尝试使用插入值ContentValues 我已将 5 个值插入到 5 列中 运行应用程序后 我只有最后一组值的行ContentValues 前四组未插入 ContentValues cv new ContentValues cv pu
  • 如何在Android中隐藏应用程序标题? [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 我想隐藏应用程序标题栏 您可以通过编程来完成 import android app Activity import android os
  • 使用 eclipse 配置mockito 时出现问题。给出错误:java.lang.verifyError

    当我将我的mockito库添加到类路径中 并使用一个简单的mockito示例进行测试时 我尝试使用模拟对象为函数add返回错误的值 我得到java lang verifyerror 以下是用于测试的代码 后面是 logcat Test pu
  • 我可以在主线程上读取一个小 txt 文件,还是应该始终避免那里的 I/O?

    我正在读取一个小的 json 文件 其中有几行 它存储在用户设备的内部应用程序文件夹中 我所做的就是这样 JSONObject jsonObject new JSONObject MyUtils inputStreamToString My
  • 在 Android SDK 中通过单击按钮更改背景颜色不起作用

    我有一个简单的程序 可以在单击按钮后更改背景颜色 但它不起作用 public class ChangeBackgroundActivity extends Activity Called when the activity is first
  • Java中如何限制文件大小

    我正在我的应用程序中创建一个文件 并继续向该文件中写入一些内容 但是当我的文件达到一定大小 比如说 100 行 后 我想删除第一行并将新行写入底部 要求是我的文件应该受到限制 但它应该保留我写入文件的最新内容 请告诉我在Java中是否可行
  • Admob - 没有广告可显示

    你好 我尝试制作一些在 Android 手机上显示广告的示例程序 并尝试在 v2 2 的模拟器上测试它 代码中的一切似乎都很好 但调试器中的 AdListener 表示 响应消息为零或空 onFailedToReceiveAd 没有广告可显
  • RecyclerView元素更新+异步网络调用

    我有一个按预期工作的回收视图 我的布局中有一个按钮可以填充列表 该按钮应该进行异步调用 根据结果 我更改按钮的外观 这一切都发生得很好 但是 当我单击按钮并快速向下滚动列表时 异步调用的结果会更新新视图的按钮 代替旧视图的视图 我该如何处理

随机推荐

  • Team Foundation Server 无法构建。缺少库或组件?

    我正在尝试使用 TFS 和构建服务器创建构建 这是我第一次尝试构建服务器 但进展并不顺利 我正在使用 Visual Studio 2012 和 TFS 2012 该项目是用 VB Net 编写的 并使用了相当多的参考资料 当我在我的开发机器
  • windows下是否可以删除某个进程打开的文件?

    出于测试和模拟的目的 我想删除我的进程当前打开的文件 The 创建文件文档 http msdn microsoft com en us library aa363858 28v VS 85 29 aspx声明可以以某种模式打开文件 FILE
  • 无法打开主机 WCF REST 服务

    我正在尝试实现一些 WCF 和 REST 服务来在我的服务器上上传文件 并且我找到了一些我正在尝试实现的代码 但尚未成功 My code class Program static void Main string args string a
  • 如何设置 Dojo 对话框打开的位置?

    我有一个 Dojo 对话框 当用户单击页面上的元素时会打开该对话框 我想控制它打开的位置 我真的希望它在单击的其他 dom 元素旁边 相对于 打开 但我似乎可以弄清楚如何执行上述任一操作 感谢您的任何建议 打开一个与 dojo 相对于单击位
  • 引入预检 CORS 请求背后的动机是什么?

    跨域资源共享是一种允许网页向另一个域 从维基百科 https en wikipedia org wiki Cross origin resource sharing 过去几天我一直在摆弄 CORS 我想我对一切的工作原理有了很好的理解 所以
  • 在浏览器中播放 HTML5 视频 - 什么适用于大多数 Android 设备?

    我正在尝试让 HTML5 视频在移动设备上播放 它们似乎在最新版本的 iOS 上运行良好 但在 Android 设备上却出现了很多不一致的情况 我正在使用 video js 并监听缩略图上的点击 这反过来会用 HTML5 视频替换该元素并自
  • 当每个字符位于一个 div 中时,如何分别对它们应用样式?

    我想为我的一个 div 的每个字母提供不同的背景 CSS 样式 例如 div class hello 1999 div 所以每个词背后都有一个类似计数器的背景 以供参考 如何在不将 div 类一一分离的情况下做到这一点 如果您想在页面加载后
  • 关于重定向的 Google 脚本无法正常工作并出现特殊错误,发生了什么

    相同的代码 从未修改过 然而 自 9 月份以来 javascript top location href https and window open https top 以上所有内容都停止工作并且出现错误 尝试导航顶级窗口的框架使用 允许用
  • 最新 PlayServices 8.3 中的 GoogleSignInAccount 内部崩溃

    Play 服务的最新版本 8 3 存在与 GoogleSignInAccount 相关的问题 我们收到了由此产生的崩溃 这是堆栈跟踪 Android 4 4 4 Manufacturer Sony Model D5503 Date Thu
  • C 中的递归。将非递归函数变成递归函数

    gcd 应该是一个递归函数 它应该返回 void 它应该采用两个正整数并将 GCD 放在第三个参数中 这是我编码的 gcd 函数 然而 我意识到这不是一个递归函数 我如何更改此代码 使其成为递归函数 void gcd int x int y
  • 如何使用 Access VBA 在 textBox.Setfocus 之后选择 TextBox 中的所有文本

    当我单击 或双击 Access 表单的文本框中时 我需要选择其中的所有文本 我尝试了以下代码 但没有成功 Me txt CompraPreco SelStart 0 Me txt CompraPreco SelLength Len Me t
  • Java 双重比较 epsilon

    我编写了一个类 用 Java 中的两个双精度数来测试相等 小于和大于 我的一般情况是比较价格 精确度可以达到半美分 59 005 与 59 395 相比 我选择的 epsilon 适合这些情况吗 private final static d
  • 向面板添加垂直滚动条

    我正在尝试做一个Panel可滚动 但只能垂直滚动 所以AutoScroll不起作用 因为子控件必须越过左边缘 那么这是如何做到的呢 尝试 仅 垂直滚动 自动滚动需要为 false 才能接受更改 mypanel AutoScroll fals
  • 在 R 中设置 kmeans 的静态中心

    我想根据预先确定的中心点 my center Points 对长和纬度 my long lats 列表进行分组 当我跑步时 k lt kmeans as matrix my long lats centers as matrix my ce
  • 使用 UIPasteBoard 复制图像 (Swift)

    我最近看到这个项目 用户可以从自定义键盘上点击 GIF 他们会看到一个 复制的 工具栏出现 我有一个问题 如何在产品中重现此工具提示GIF 教程 http o aolcdn com hss storage midas 27c2fb5dfec
  • jQuery 灯箱画廊

    是否存在具有标准灯箱功能的 jQuery 插件 在 灯箱 窗口中 我想在同一 灯箱 窗口中的某处 左侧 底部等 将当前图像和其余图 像显示为缩略图 ColorBox http colorpowered com colorbox 一个轻量级
  • 对 Automapper 配置文件进行单元测试

    我的确想要测试自定义逻辑CreateMap方法 我愿意NOT想要测试某些类型的映射是否存在 我该怎么做或者我需要知道哪些课程 我很感激该文件的每一个提示 Automapper 单元测试似乎很少见 public class UnitProfi
  • 计算 numpy.chararray 中字符出现次数的最快方法

    Python主义者 计算字符在字符中出现的最快方法是什么numpy character array 我正在做以下事情 In 59 for i in range 10 m input Enter A or B rr 0 i m Enter A
  • 使用 ASP MVC 下载并显示私有 Azure Blob

    我将 ASP MVC 5 Razor 与 Microsoft Azure Blob 存储结合使用 我可以使用 MVC 成功地将文档和图像上传到 Blob 存储 但我很难找到一些如何下载和显示文件的 MVC 示例 如果 blob 存储为公共文
  • ConstraintLayout 不会省略 TextView 中的长文本

    我有一个TextView在图像的右侧 我试图在图像旁边放置一些长文本 但该文本应通过在末尾添加 自动结束 然而 这是行不通的 我使用这个布局