更改按钮上文本的方向

时间:2013-03-06 11:39:24

标签: android orientation

我如何改变按钮中文本的方向,使它们垂直而不是水平书写?

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

有可能吗?

3 个答案:

答案 0 :(得分:7)

这是将宽度设置为12dp后的屏幕截图

enter image description here

试试这个

在您的字符串中添加\n个字符,以便Strings.xml中的换行符 像这样

1\n 2\n 3\n

你可以像这样直接设置

android:text="@String/yourstring"

答案 1 :(得分: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函数

答案 2 :(得分:0)

我自己修好了。我创建了一个名为layout-land的独立文件夹,并在其中放置一个单独的XML文件来处理它。现在布局看起来都很好,我可以使用硬编码权重。