我有什麼如果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中預覽和裝置執行的代碼後:
我需要什麼
我需要顯示的前綴「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>
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和它一樣好幫助我進一步調查問題。感謝大家的幫助!
在你的行中加入一個額外的/例如'https:///'第一個/ //是一個轉義字符 –
感謝Jonathan,我試過這個:「https:///」,結果相同。 ..也試過「https:\/\ /」但沒有效果... – jcasadellaoller