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>
相关推荐
逐光老顽童2 天前
Java 与 Kotlin 混合开发避坑指南:30 个真实案例实录
android·kotlin
爱勇宝2 天前
鸿蒙生态的下半场:开发者不只要能开发,还要能赚钱
android·前端·程序员
Yeyu2 天前
刷新一帧的艺术:invalidate / postInvalidate / postInvalidateOnAnimation全解析
android
潘潘潘2 天前
Android OTA 升级原理和流程介绍
android
plainGeekDev3 天前
null 判断 → Kotlin 可空类型
android·java·kotlin
plainGeekDev3 天前
getter/setter → Kotlin 属性
android·java·kotlin
YXL1111YXL3 天前
Handler 消息回收与协程异步执行的时序陷阱
android
恋猫de小郭3 天前
KMP / CMP 鸿蒙版本 Beta 发布,他有什么特别之处?
android·前端·flutter
三少爷的鞋3 天前
Android 协程并发控制:别动线程池,控制好并发语义就够了
android
weiggle3 天前
第七篇:状态提升与单向数据流——架构设计的核心
android