问题
i am a new android developer,i know align two text in one button using by /n, but don't know align two text in one button one text right alignment and another one is left align please any one help me and solve my problem, since I use Arabic language (right to left) I want to do this programmatically, not by xml design. I need to align two texts one below another ie, english text on top and arabic in bottom Thanks in advance
回答1:
Use following code:
Button availableText = (Button)findViewById(R.id.request);
Spannable span =Spannable.Factory.getInstance().newSpannable(availableText.getText());
span.setSpan(new AlignmentSpan.Standard(Alignment.ALIGN_NORMAL),0, 7,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
span.setSpan(new AlignmentSpan.Standard(Alignment.ALIGN_OPPOSITE),8,
span.length()-1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
availableText.setText(span);
Assuming you have a button defined in XML or can create one in code with text "English\nArbi".
The output is as follows:

来源:https://stackoverflow.com/questions/10738648/how-to-align-two-text-in-one-button