2013-02-08 106 views
0

這裏是我的代碼:的Android如何適應TEXTSIZE中的TextView

<LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="120dp" 
       android:orientation="vertical" 
       android:layout_weight="3" 
       android:weightSum="4"> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="0dp" 
        android:layout_weight="1" 
        android:text="P" /> 
       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="0dp" 
        android:layout_weight="2" 
        android:text="Bryant" /> 
       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="0dp" 
        android:layout_weight="1" 
        android:text="27" /> 
      </LinearLayout> 

當outest佈局的高度爲120dp,文字無法顯示完整的單詞(如「Y」只SHWO上部) ,我認爲這是因爲文字太大。
但是,當我設置爲150dp時,文本可以顯示整個單詞。
是否有任何方法來設置文本的文本大小自動適合textview顯示整個單詞。
我不想將textsize硬編碼爲12sp。
而且,我只想在xml中做。
謝謝。

+0

你有沒有想過將你的LinearLayout設置爲'wrap_content'而不是120dp? – Wenhui 2013-02-08 17:33:21

+0

或設置你的文字視圖高度爲'wrap_content' – FoamyGuy 2013-02-08 17:37:28

+0

我只是看不到任何理由爲什麼它不顯示整個文本...你會介意發佈整個xml嗎?因爲儘可能多的我可以看到,你只是比你的文字高度,所以他們應該被看到。 120dp就足夠4個文本的默認文本大小,我假設... – yahya 2013-02-08 18:48:32

回答

0

不幸的是,沒有簡單的方法來爲TextView自動調整字體大小。我建議使TextView的wrap_content爲高度,而不是靜態高度。

如果您發現屏幕上沒有足夠的空間,可能是將整個東西包裹在ScrollView中?

<ScrollView android:layout_width="fill_parent" android:layout_height="120dp"> 
    <LinearLayout android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="P" /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Bryant" /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="27" /> 
    </LinearLayout> 
</ScrollView> 
0

沒有辦法自動更改字體大小來調整文本以適合特定大小。

0

不僅沒有自動適合文字,但實施也是not trivial

我會推薦另一種UI方法。這會讓你頭痛後頭疼。

相關問題