2013-03-06 128 views
1

我該如何改變按鈕中文本的方向,以便它們垂直寫入而不是水平寫入?更改按鈕上文本的方向

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_weight="0.10" 
    android:text="Previous" /> 

這可能嗎?

+0

我認爲如果你設置的按鈕是垂直的(形狀因子),文本應該如下。另一件事是如果你想要文本垂直顯示,從下到上。 – g00dy 2013-03-06 11:44:31

+0

看看這個問題.... http://stackoverflow.com/questions/8604932/android-text-view-text-in-vertical-direction – 2013-03-06 11:46:34

+0

或者你可以用喜歡使用Html.fromHtml()打破例如小號
一個
,不是高貴的解決方案,但將努力 – Waqas 2013-03-06 11:47:03

回答

0

我固定它自己。我製作了一個名爲layout-land的獨立文件夾,並在其中放置了一個單獨的XML文件來處理這個問題。現在佈局看起來都很好,我可以使用硬編碼權重來表示屬性。

2

試過並測試過這個,它的工作非常好。

public class buttonCustom extends Button{ 
String s=""; 

public buttonCustom(Context context) { 
    super(context); 
} 


public buttonCustom(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    // TODO Auto-generated constructor stub 
} 


public buttonCustom(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    // TODO Auto-generated constructor stub 
} 


@Override 
public void setText(CharSequence text, BufferType type) { 
    // TODO Auto-generated method stub 

    // TODO Auto-generated method stub 

    for(int i=0;i<text.length();i++) 
    { 
     if(s==null) 
      s=""; 

     s= s+String.valueOf(text.charAt(i))+ "\n"; 
    } 



    super.setText(s, type); 
} 

}

改寫按鈕類和重寫的setText功能

7

這是設置寬度後的屏幕截圖到12dp

enter image description here

嘗試此

地方在串線210字符在Strings.xml 打破這樣

1\n 2\n 3\n 

,您可以直接設置它像這樣

android:text="@String/yourstring" 
+0

如果您的要求是旋轉按鈕,您可以使用旋鈕屬性爲您的按鈕 – Pragnani 2013-03-06 11:54:06

+0

Nah,它必須是按鈕中的文本。 – OmniOwl 2013-03-06 12:01:13

+0

好吧,試試我發佈的內容。 – Pragnani 2013-03-06 12:02:51