2013-03-06 110 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