Justify android text inside a textview without using a WebView

1.7k Views Asked by At

I want to justify the text inside the textview.Is there any way to justify the content inside the textview.I don't want to use webview...Is there a library for it??Plz help me...Thanks in advance..

Justify.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     android:background="@drawable/back1"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/banner" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="120dp"
        android:layout_marginTop="20dp"
        android:text="About Us" />

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="true" >

            <TextView
                android:id="@+id/textView"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"

                android:layout_weight="0.94"
                android:text="Paragraph\n\nParagraph"

    </ScrollView>

Activity

public class About_us extends Activity {
TextView txtName;
TextView txtName1;
    @SuppressLint("NewApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about_us);
        getActionBar().setDisplayHomeAsUpEnabled(true);
        txtName = (TextView) findViewById(R.id.textView);
        txtName.setTextColor(Color.WHITE);
        txtName1 = (TextView) findViewById(R.id.textView1);
        txtName1.setTextColor(Color.WHITE);
        txtName1.setTextSize(16);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.about_us, menu);
        return true;
    }
1

There are 1 best solutions below

0
On

Android does not support full justify in TextView by default. You have to use WebView for that, but as you dont wanna use Webview. So, the Solution is ANDROID Text-Justify 2.0 Library.

You can find that Library on following github link

https://github.com/bluejamesbond/TextJustify-Android

Full setup information is provided on the same link.