1

Try to justify text but i am not able to do that i want to start text start an end at equal margin from both left and right side. How to do that?

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="20dp"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:lineSpacingExtra="4dp"
        android:layout_marginRight="3dp"
        android:layout_marginLeft="3dp"
        android:paddingBottom="20dp"
        android:text="@string/about_us"
        android:textColor="@color/black"
        android:textSize="15sp"/>
</LinearLayout>
Linh
  • 57,942
  • 23
  • 262
  • 279
Ankita Sethi
  • 43
  • 2
  • 11
  • you can check it http://stackoverflow.com/questions/1292575/android-textview-justify-text – Linh Feb 13 '17 at 03:34

3 Answers3

2

Android doesn't support justified text yet.

You can use an external library to do your work.

I recommend this:

https://github.com/nikoo28/justify-textview-android

mVck
  • 2,910
  • 2
  • 18
  • 20
Harry T.
  • 3,478
  • 2
  • 21
  • 41
0

First of all Android do not support full justification, but if you want to justify your text try this way

Just add to your build.gradle

dependencies {
    compile 'com.github.bluejamesbond:textjustify-android:2.1.6'
}

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

OR

Try this way

public class MainActivity extends Activity {

    private JustifiedTextView mJTv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mJTv=(JustifiedTextView) findViewById(R.id.activity_main_jtv_text);
        mJTv.setText(getResources().getString(R.string.test));
        mJTv.setTextSize(TypedValue.COMPLEX_UNIT_SP,20);
        mJTv.setLineSpacing(15);
        mJTv.setBackgroundColor(Color.RED);
        mJTv.setAlignment(Align.LEFT);
        mJTv.setTypeFace(Typeface.createFromAsset(getAssets(), "fonts/naskh_bold.ttf"));

    }
}

XML

<ir.noghteh.JustifiedTextView
        android:id="@+id/activity_main_jtv_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:padding="25dp"
        xmlns:noghteh="http://noghteh.ir"
        noghteh:text="@string/hello_world"
        noghteh:textColor="@color/text"
        noghteh:textSize="18sp"
       >
    </ir.noghteh.JustifiedTextView>

https://github.com/navabi/JustifiedTextView

Aditya Vyas-Lakhan
  • 13,409
  • 16
  • 61
  • 96
0

Justify text in textview android.


String dis="You can write your content here";

String text_string="<html><body style=\"text-align:justify\">"+dis+"<body><html>";

TextView text=setText(fromHtml(text_string));