簡體   English   中英

更改按鈕上文本的方向

[英]Change orientation of text on a Button

我將如何更改按鈕中文本的方向,以使其垂直而不是水平書寫?

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

可能嗎?

這是將寬度設置為12dp后的屏幕截圖

在此處輸入圖片說明

嘗試這個

在您的字符串中放置\\n字符,以便像這樣在Strings.xml換行

1\n 2\n 3\n

你可以像這樣直接設置

android:text="@String/yourstring"

嘗試並測試了它,它的工作原理絕對不錯。

 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函數

我自己修好了。 我制作了一個名為layout-land的單獨文件夾,並在其中放置了一個單獨的XML文件來解決這個問題。 現在兩者的布局看起來都不錯,並且我可以對屬性使用硬編碼的權重。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM