how to align two text in one button

我与影子孤独终老i 提交于 2020-01-04 11:41:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!