2015-01-09 55 views
0

我有這個textviews如何使文本的一部分TextView的大膽

((TextView)findViewById(R.id.carmodel)).setText("CarModel: " + getCarModel+""); 
((TextView)findViewById(R.id.bikemodel)).setText("BikeModel: " + getBikeModel+""); 

有沒有一種方法,大膽只是CarModel:BikeModel:? 這是xml文件

<TextView 
    android:id="@+id/carmodel" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dp" 
    android:textSize="17sp" 
    android:textStyle="italic" 
    android:layout_marginLeft="10dp" 
    android:text="" 
    android:textAppearance="?android:attr/textAppearanceSmall" /> 

<TextView 
    android:id="@+id/bikemodel" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dp" 
    android:textSize="17sp" 
    android:textStyle="italic" 
    android:layout_marginLeft="10dp" 
    android:text="" 
    android:textAppearance="?android:attr/textAppearanceSmall" /> 

所以getCarModel和getBikeModel將是斜體和CarModelBikeModel:大膽..

回答

2

有很多方法可以實現你想要什麼。

1)由 「塔尼斯」 在這裏解釋您可以將文本視圖中插入HTML 「How to display HTML in TextView?

((TextView)findViewById(R.id.carmodel)).setText(Html.fromHtml("<h2>CarModel: </h2>") + getCarModel+""); 

2)您可以創建兩個文本視圖像

((TextView)findViewById(R.id.carmodelBold)).setText("CarModel: ");  
((TextView)findViewById(R.id.carmodel)).setText(getCarModel); 

和風格只要你想要的文本視圖ID「carmodelBold」。

3)您可以創建一個表

+0

我已經編輯我的問題,並且增加了XML – Goro

+0

可能是第二種方式會幫助我,但如何把它們放在一排?因爲如果我爲粗體文本製作一個文本視圖而另一個數據則在不同的行上? – Goro

+0

我相信你正在使用垂直方向的lineraLayout。你需要使用linearLayout和水平方向。 – Ankit