2015-08-20 58 views
0

我正在接收數據並應以特定方式顯示這些數據的Android應用程序。我收到三個字符串(例如A,B和C),並且我必須將這些添加到我自己創建的TextView中,以這種方式:在TextView中對齊文本的部分

| A B C |

A必須對齊左邊,B對齊中心,C對齊右邊。 我真的不知道該怎麼做; TextView的尺寸可以改變取決於用於運行應用程序的屏幕的大小,但是這些字符串必須位於我在每種可能情況下顯示的位置。

感謝您的幫助!

ps:是否有可能在BOLD中顯示這些字符串?

回答

0

試試這個....

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    android:weightSum="3" > 

    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="left" 
     android:text="Text1" 
     android:textStyle="bold" /> 

    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="center_horizontal" 
     android:text="Text2" 
     android:textStyle="bold" /> 

    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="right" 
     android:text="Text3" 
     android:textStyle="bold" /> 

</LinearLayout> 
1

1)請使用3xTextView內的LinearLayout,取向水平

2)的LinearLayout android:width="match_parent"

3)在文本視圖設置android:layout_gravity爲A)left B)center C)right

4)爲TextView集android:layout_weight=1

加粗textView: android:textStyle="bold"