Justified Alignment in Android

Alternatively referred to as align or alignment, justify is a term used to describe how text is aligned. For example, text that is justified to the left creates a straight line of text on the left-hand side of the page (like this paragraph). Text can be aligned along the edge of a page, cell, div, table, or other visible or non-visible line. Below are some different examples of aligned text.


Alignment is only a small piece of the puzzle. What works for one design might be totally inappropriate for another layout. As with all layouts, it depends on the purpose of the piece, the audience and its expectations, the fonts, the margins and white space, and other elements on the page. The most appropriate choice is the alignment that works for that particular design.

In this example we will see how we can justify text in web view and text view. As we all know android does not supports full justification of text in a textview. It does not have in-built option for it. However, you can justify text in android using WebView. The trick is to use HTML tags with justify alignment so that the text gets aligned properly. In your main Activity, add a WebView as follows:




Write following into your main xml file:




You cannot apply the same trick for TextView since Android does not support full justification at present. However TextView in Android is a complete text editor that helps us to display text to the user. TextView also optionally allows the user to edit the text, though the basic class is configured to not allow editing.

Justifying the text means aligning the text from both sides i.e. Left Hand Side and Right Hand Side.

1.) Create an XML file and drag the TextView and write some text in it.




2.) Define the XML in the Main Activity to get the main screen displayed.




3.) Create an XML file in the ‘Value’ folder with the name justifiedtextview_attr.xml for the justification attributes. It will contain the below points:
4.) Define the XML Code for justification in Main.Xml.




5.) Create another Class named – justificationClass.This class is used to implement the code for justification with the help of HTML to fetch data and set it in TextView with the justified format.




The type alignment setting is sometimes referred to as text alignment, text justification or type justification. The edge of a page or column is known as a margin, and a gap between columns is known as a gutter.


Leave a Comment: