如果 TextView 大于 1 行,如何在我的 TextView 上显示省略号? [英] How can I show ellipses on my TextView if it is greater than the 1 line?

查看:25
本文介绍了如果 TextView 大于 1 行,如何在我的 TextView 上显示省略号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的以下布局不起作用:

I have the following Layout which does not work:

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:id="@+id/experienceLayout" 
    android:background="#ffffff" 
    android:layout_height="match_parent" 
    android:paddingLeft="6dp" 
    android:paddingRight="6dp" 
    android:paddingBottom="6dp" 
    android:paddingTop="6dp">

    <TextView 
        android:layout_weight="1" 
        android:id="@+id/experienceLabel" 
        android:text="Experience" 
        android:layout_height="wrap_content" 
        android:textColor="#000000" 
        android:layout_width="wrap_content" 
        android:textStyle="bold">
    </TextView>

    <TextView 
        android:id="@+id/experienceTextView" 
        android:text="TextView" 
        android:layout_height="wrap_content" 
        android:textColor="#000000" 
        android:layout_width="wrap_content" 
        android:ellipsize="end" 
        android:lines="1" 
        android:maxLines="1" 
        android:singleLine="true" 
        android:fadeScrollbars="false">
    </TextView>

</LinearLayout>

推荐答案

这是一个常见问题.尝试使用以下方法:

This is a common problem. Try using the following:

android:scrollHorizontally="true"
android:ellipsize="end" 
android:maxLines="1"

................. scrollHorizo​​ntally 是使它起作用的特殊调味料".

.............. the scrollHorizontally is the "special sauce" that makes it work.

这篇关于如果 TextView 大于 1 行,如何在我的 TextView 上显示省略号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆