In my app first I have textview to show text. Then I want to justify text but in android its not possible to justify text in textview. To justify text I am taking help from this link. I am following the answer provided by @Kondzio but its not working. I dont know whats wrong in my code.
Code-
public class Benefits extends Activity{
private Button back;
LinearLayout bText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.benefits);
WebView view = new WebView(this);
view.setVerticalScrollBarEnabled(true);
((LinearLayout)findViewById(R.id.bText)).addView(view);
view.loadData(getString(R.string.benef), "text/html", "utf-8");
back.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{
finish();
}
});
}
}
Xml-
<LinearLayout
android:id="@+id/bText"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:gravity="center">
</LinearLayout>
In strings.xml-
<string name="benef">
<![CDATA[
<html>
<head></head>
<body style="text-align:justify;color:gray;background-color:black;">
"1.some text\n
2.some text\n
.............
</body>
</html>
]]>
</string>
I am setting scrollbarenabled to true to make vertical scrolling on my text.
Copy the following class to your project and extend your textview from this:
JustifiedTextView.java :
You can use it like this:
If your text view is in xml, edit it like this:
The do this in your code:
first Create new class JustifyTextView.java its alignment the Textview text in center. Am attached full code below
Then go to your xml code replace your textview by this code
To justify text in text view, use this in your XML:
and use this in the Java class:
// converting all the language content to justify using html tags.
EDIT: or change your code with added back slash
How to justify text in Android without using any Library See More code.
Create a activity and paste following code See More