从原始位置移动了具有省略号属性的Android TextView
我发现Android TextView和ellipsize属性有一个奇怪的行为。 当文本较长且应用了“ellipsize”属性时,文本的原始位置将丢失,文本将显示得稍高一些 是的,我可以通过编程来解决它,但是我想知道它是否是一个bug或者我做错了什么 一个非常简单的例子来测试它。 更改两个文本视图的文本,以查看省略的文本或与上一个屏幕截图中显示的文本不同的文本。如果你比较屏幕截图,你会发现问题所在 我用“dp”和“sp”测试了它,看看它是否可能是一种不同的行为。但事实并非如此从原始位置移动了具有省略号属性的Android TextView,android,textview,attr,longtext,Android,Textview,Attr,Longtext,我发现Android TextView和ellipsize属性有一个奇怪的行为。 当文本较长且应用了“ellipsize”属性时,文本的原始位置将丢失,文本将显示得稍高一些 是的,我可以通过编程来解决它,但是我想知道它是否是一个bug或者我做错了什么 一个非常简单的例子来测试它。 更改两个文本视图的文本,以查看省略的文本或与上一个屏幕截图中显示的文本不同的文本。如果你比较屏幕截图,你会发现问题所在 我用“dp”和“sp”测试了它,看看它是否可能是一种不同的行为。但事实并非如此 <?xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
<View
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="50dp"
android:background="@android:color/holo_green_dark" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="23.3dp"
android:ellipsize="end"
android:maxLines="1"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="Hello World! (dp textSize)"
android:textColor="@android:color/black"
android:textSize="25dp" />
<View
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="150dp"
android:background="@android:color/holo_blue_dark" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="123.2dp"
android:ellipsize="end"
android:maxLines="1"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="Hello World! (sp textSize)"
android:textColor="@android:color/black"
android:textSize="25sp" />
</RelativeLayout>
解决方案:
解决方法是使用“singleLine”属性,然后问题消失。但是AndroidStudio告诉我“单线不推荐使用”。我对字体“Courier New”也有类似的问题——当一行文字被省略时,它向下移动了几个像素。 我的问题的解决方案是添加:
android:includeFontPadding="false"
无论我在哪里使用这种字体。我对字体“Courier New”也有类似的问题——当一行文字被省略时,它向下移动了几个像素。 我的问题的解决方案是添加:
android:includeFontPadding="false"
无论我在哪里使用这种字体。解决方法是使用“singleLine”属性,然后问题就消失了。但是AndroidStudio告诉我“singleLine不推荐使用”。解决方法是使用“singleLine”属性,然后问题就消失了。但是AndroidStudio告诉我“singleLine已被弃用”。我会看看这个选项。谢谢我来看看这个选项。谢谢