简体   繁体   English

更改按钮上文本的方向

[英]Change orientation of text on a Button

How would I go about changing the orientation of the text in my buttons, so that they are written vertically rather than horizontally? 我将如何更改按钮中文本的方向,以使其垂直而不是水平书写?

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

Is it possible? 可能吗?

This is the screenshot after setting the width to 12dp 这是将宽度设置为12dp后的屏幕截图

在此处输入图片说明

Try this 尝试这个

place \\n character in your string for line breaks in your Strings.xml like this 在您的字符串中放置\\n字符,以便像这样在Strings.xml换行

1\n 2\n 3\n

and you can directly set it like this 你可以像这样直接设置

android:text="@String/yourstring"

Tried and tested this one it's working absolutely fine. 尝试并测试了它,它的工作原理绝对不错。

 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);
}

} }

Override button class and override the setText function 覆盖按钮类并覆盖setText函数

I fixed it myself. 我自己修好了。 I made a separate folder called layout-land and put a separate XML file in there to take care of that. 我制作了一个名为layout-land的单独文件夹,并在其中放置了一个单独的XML文件来解决这个问题。 Now the layout looks fine in both, and I can use hardcoded weights for attributes. 现在两者的布局看起来都不错,并且我可以对属性使用硬编码的权重。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM