2016-05-31 51 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