Android 如果maxLines=1,为什么要在TextView中对文本进行字符/剪切?

Android 如果maxLines=1,为什么要在TextView中对文本进行字符/剪切?,android,view,textview,special-characters,Android,View,Textview,Special Characters,我拥有的 我有一个TextView,它显示一个前缀为“https://”的URL: 有什么问题吗? 执行代码后,android studio预览和设备中的结果为: 如果执行上一个代码: 如果我删除“/”符号: 如果我将符号移动到其他位置: 我需要什么 我需要显示前缀“https://”,最大字母数以适应可用空间 我尝试的 我试图(设置块)并在stackoverflow中搜索,搜索带有此符号的引用,但未找到任何结果。 我还试图在没有效果的情况下替换这些符号 有人知道为什么会这样,能帮

我拥有的

我有一个TextView,它显示一个前缀为“https://”的URL:


有什么问题吗?

执行代码后,android studio预览和设备中的结果为:

如果执行上一个代码:

如果我删除“/”符号:

如果我将符号移动到其他位置:



我需要什么

我需要显示前缀“https://”,最大字母数以适应可用空间

我尝试的

我试图(设置块)并在stackoverflow中搜索,搜索带有此符号的引用,但未找到任何结果。 我还试图在没有效果的情况下替换这些符号

有人知道为什么会这样,能帮我吗?提前谢谢

更新布局

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="15dp"
    android:paddingBottom="15dp"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="@string/icon_unchecked"
        android:layout_marginRight="10dp"
        android:id="@+id/txvIconChecked"/>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="test2"
            android:maxLines="1"
            android:ellipsize="marquee"
            android:textStyle="bold"
            android:textSize="16sp"
            android:textColor="@color/primary_text"
            android:id="@+id/txvNomEntornIversio" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="https://mydomain.asdfasdasdfasdfasdffasdfasdfasdf.cat"
            android:ellipsize="end"
            android:maxLines="1"
            android:paddingLeft="10dp"
            android:textSize="13sp"
            android:textStyle="italic"
            android:id="@+id/txvUrlEntorn"/>

    </LinearLayout>

</LinearLayout>

更新2

多亏了Teiky,我们发现这个问题只发生在低于API 23的版本中。可能是虫子

选项(已弃用)Android:SingleLine=“true”似乎在所有版本中都能正常工作!相反,新选项android:MaxLines和android:ellipsize只适用于23

目前,最可行的选择似乎是忽略不推荐的单线

我的解决方案

最后,正如我在上次更新中所说,我的解决方案是继续使用android:SingleLine=true,即使它被标记为不推荐使用

第二秒,他尝试了dipsositiu android 4.4.4,使用MaxLines ellipsize运行良好。。。而我,一个棒棒糖装置,我仍然剪下文字来寻找符号/


作为对帝京的回应,它帮助我进一步调查了这个问题。谢谢大家的帮助

我尝试了您的代码,URL已完全显示。 如果您有足够的宽度来显示完整的URL,也许您应该检查这些参数:

android:layout_width="0dp"
android:layout_weight="1"
XikitidInstant更新:


解决方案不是重量和宽度=“0dp”。这是一个代码改进。问题中更新了我的解决方案。感谢您的帮助。

在您的行中添加一个额外的/:例如
https://
中的第一个/是转义字符谢谢Jonathan,我尝试了以下方法:“https://”,结果相同。。。还尝试了“https:\/\/”,但没有效果…谢谢Teiki。你是对的,如果我的url适合,这是正确显示。但我的胜利在于,当URL无法放入可用空间时,显示尽可能多的URL,并在最后添加三点。。。我用新的视图更新了代码。哇,这太棒了!我不明白为什么这对我不起作用。。。。也许becouse是NavigationDrawer左菜单中的一项,具有固定的240dp宽度?让我试着编译最后的更改…如果你看一下android studio的预览视图,你也看对了吗?哇!如果将目标更改为API23,它的工作方式与快照类似。尝试将其更改为低于23。。。这似乎是解决了新的API 23是你的权利。使用API 22,预览会像您所说的那样截断URL。你试过模拟器吗?也许问题只是出现在预览中
android:maxLines="1"
android:ellipsize="end"
android:maxLines="1"
android:ellipsize="end"