Skip to content Skip to sidebar Skip to footer

How To Align Two Text In One Button

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 ple

Solution 1:

Use following code:

ButtonavailableText= (Button)findViewById(R.id.request); 
            Spannablespan=Spannable.Factory.getInstance().newSpannable(availableText.getText());
            span.setSpan(newAlignmentSpan.Standard(Alignment.ALIGN_NORMAL),0, 7, 
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
            span.setSpan(newAlignmentSpan.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:

Button layout example

Post a Comment for "How To Align Two Text In One Button"