2016-01-23 30 views
1

我創建一個應用程序,我希望文字按鈕下allign,它看起來像這樣的切割: enter image description here文本對齊,如果太長

,所以我想大文本開始在左邊的(5dp),按鈕結束(距左側155dp)結束。如果文本太長而無法放在按鈕下方,我不希望它進入下一行,我希望它在最後切入並放入「..」,以便它看起來像這個f.e. 「大T ..」,我photoshoped那張照片真正的快向你展示我的意思:

enter image description here

我有點新的XML和整個ndroid應用場景,所以任何幫助表示讚賞: )

+0

是你的大文本動態? – Mohit

+0

正如我所說,我是新來的,所以請原諒,但我不知道你的意思與「動態」,或者我怎麼可以檢查它是否是動態的線索 –

+0

你能顯示你的佈局xml嗎? –

回答

1

使用LinearLayoutslayout_wight。下面的示例代碼:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

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

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@android:drawable/ic_menu_save"/> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@android:drawable/ic_menu_save"/> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@android:drawable/ic_menu_save"/> 


</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="5dp" 
    android:layout_marginRight="5dp" 
    android:orientation="horizontal"> 

    <Button 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:singleLine="true" 
     android:text="LOOOOOOOOOOOOOOOOOOOOONG"/> 

    <Button 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:singleLine="true" 
     android:text="LOOOOOOOOOOOOOOOOOOOOONG"/> 

    <Button 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:singleLine="true" 
     android:text="LOOOOOOOOOOOOOOOOOOOOONG"/> 


</LinearLayout> 

結果將是:

enter image description here

+1

不錯的一個,解決方案看起來不錯 – Tasos

1

在你的TextView添加這些屬性:

android:ellipsize="end" 
android:maxEms="8" 
android:singleLine="true" 

注意:您可以調整EMS大小你想要顯示多少個字符。