2016-05-31 53 views
1

我有什么如果maxLines = 1,为什么字符/剪切TextView中的文本?

我是谁出以 “https://” URL的TextView的前缀:

<LinearLayout 
     android:orientation="vertical" 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     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://test2.sdasasdasdfasdfasdffasdfasdfasdf.sdffd" 
      android:ellipsize="end" 
      android:maxLines="1" 
      android:paddingLeft="10dp" 
      android:textSize="13sp" 
      android:textStyle="italic" 
      android:id="@+id/txvUrlEntorn"/> 

    </LinearLayout> 

是什么问题?

结果在Android Studio中预览和装置执行的代码后:

如果执行以前的代码: enter image description here

如果我删除了 “/” 符号: enter image description here

如果我将符号移动到其他位置: enter image description here



我需要什么

我需要显示的前缀“https://开头”最大字母以适合可用空间。

是我的尝试

我试图read documentation(setEllipsize块)和计算器搜索,搜索与该符号并没有什么发现了一些参考。 我也尝试过无效的符号。

任何人都知道它为什么会发生,并可以帮助我吗?提前致谢!

修订LAYOUT

<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> 

enter image description here

enter image description here

UPDATE 2

感谢Teiky,我们发现只有在低于API 23的版本中才会出现此问题。它可能是一个错误?

该选项(不建议使用)Android:SingleLine =“true”似乎在所有版本中都能正常工作!相反,新的选项的android:与Android MAXLINES:ellipsize仅适用于23 ...

目前,最可行的办法似乎忽略已过时SINGLELINE ...

解ME

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

帝京秒时,他尝试了dipsositiu的Android 4.4.4,并运作良好使用MAXLINES ellipsize ......和我,一个设备棒棒堂我还是剪切文本找到符号/ ...

集响应Teikyo和它一样好帮助我进一步调查问题。感谢大家的帮助!

+0

在你的行中加入一个额外的/例如'https:///'第一个/ //是一个转义字符 –

+0

感谢Jonathan,我试过这个:“https:///”,结果相同。 ..也试过“https:\/\ /”但没有效果... – jcasadellaoller

回答

1

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

android:layout_width="0dp" 
android:layout_weight="1" 

更新通过xikitidistant:

的解决方案是不重量,宽度=“0dp”。这是一个代码改进。对于我的解决方案是在问题中更新。谢谢你的帮助。

+0

谢谢Teiki。你是对的,如果我的网址适合,这是正确显示。但是,我的胜利是当网址无法放入可靠的空间时显示最大可能的URL,并在最后加上三点......我用新视图更新了代码。 – jcasadellaoller

+1

我不明白,现在有什么问题? http://imgur.com/2OcNl64 – Teiki

+0

哇,这是!我不明白为什么这不适合我....也许becouse是一个固定240dp宽度的NavigationDrawer左菜单中的项目?让我试着编译最后的更改... – jcasadellaoller