Android TextView 超出省略失效 解决方法

解决方法

我是在使用 ConstraintLayout 嵌套 LinearLayout 水平方向,TextView 又使用layout_weight(权重)情况下出现这种问题,最后将layout_width从 0dp 改为 1dp 得以解决。

XML 复制代码
<androidx.constraintlayout.widget.ConstraintLayout>
    <LinearLayout
        android:id="@+id/announcement_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="12dp"
        android:gravity="center_vertical"
        android:minHeight="28dp"
        android:orientation="horizontal"
        app:layout_constraintLeft_toLeftOf="@id/coupon_group"
        app:layout_constraintTop_toBottomOf="@id/coupon_group"
        app:layout_constraintRight_toRightOf="parent">

        <TextView
               android:id="@+id/announcement_content"
               style="@style/Font_303133_12"
               android:layout_width="1dp"
               android:layout_height="18dp"
               android:layout_weight="1"
               android:ellipsize="end"
               android:singleLine="true"                
               android:text="测试数据测试数据测试数据测试数据测试数据测试数据" />

         <ImageView
               android:id="@+id/drop_icon"
               android:layout_width="20dp"
               android:layout_height="20dp"
               android:scaleType="fitXY"
               android:src="@mipmap/drop_down_gray" />

    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
相关推荐
Mr数据杨6 小时前
【Codex】用学生入学评估模块建立新生能力画像
android·java·javascript·django·codex·项目开发
●VON7 小时前
谁小时候不想要一个游戏修改器?我把电脑 Skill 做成了 Android 小助手
android·游戏·电脑
刃神太酷啦7 小时前
Linux 系统 MySQL 完整安装配置教程:从卸载 MariaDB 到优化 my.cnf----《Hello MySQL!》(1)
android·linux·c语言·c++·mysql·leetcode·mariadb
里欧跑得慢7 小时前
Flutter 三方库 function_tree — 鸿蒙应用开发中的动态数学公式解析与计算神器,实现鸿蒙深度适配下的复杂函数逻辑运行时求值实战(适配鸿蒙 HarmonyOS Next ohos)
android·前端·安全·flutter·华为·harmonyos
IT毕设实战小研7 小时前
基于安卓的空气质量查询系统
android·大数据·vue.js·爬虫·python·django·课程设计
雨声不在10 小时前
docker-android Android 16 支持与编译修改
android
天空之城--15 小时前
【无标题】
android
mmsx16 小时前
osmdroid 接入谷歌影像底图:瓦片 URL 拼接与多域名轮询实战
android·osmdroid
ZYJCSZKJ16 小时前
基于大语言模型的地域实体语义增强:生成式引擎优化(GEO)中的多模态内容生成实践
android·人工智能·语言模型
ssshooter17 小时前
Tauri + GitHub Actions 自动化发布 Android APK 技术总结
android·github·android studio