####Update: Recent merges have broken the branch. I am working on a push that fixes most of the identified issues. This will take some refractoring and additional techniques. I will push after testing the code by the end of this week (October 25, 2014). Until then, refer to commit@8495997abb676dd86b7ee48d09a0bd6237adb5f4 which is the last known building version.
####Update 2: Download the updated version with support for Spannables!
####Update 3: Writing test cases and documentation for the new refractor. Will push after some housekeeping.
This is very simple. What you want to do is get the library itself and add it to your Android project. Upcoming
- Support for hyphenating. @muriloandrade
- Support for editable text (while justification is enabled)
- More optimizations
Been very busy lately
Looks very accurate and neat. Small issues may arise but can be easily sorted out if users post their issues on Github. To use it, all you have to do is include the TextViewEx.java
and TextJustifyUtils.java
in your project. Then you may use as you would the built-in TextView
.
To improve performance on large TextViews, you must enable optimization. To do so, you must use setDrawingCacheEnabled(bool)
. Uing this increases speed, but it also requires more memory.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<com.textjustify.TextViewEx
android:id="@+id/textview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextViewEx txtViewEx = (TextViewEx) findViewById(R.id.textViewEx);
txtViewEx.setText("Insert your content here", true); // true: enables justification
// Optional hyphenation:
// Words syllables must be pre-separated with a syllableSeparator string (character)
// Example: A com*put*er is a gen*er*al pur*pose de*vice that...
txtViewEx.setHyphenate(true, "*");
}
Comparison
This would be considered a fallback option in the case the previous option did not work for you. To use this, include TextJustifyUtils.java
and follow the sample code below.
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView txtView = (TextView) findViewById(R.id.textView);
txtView.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener()
{
boolean isJustified = false;
@Override
public boolean onPreDraw()
{
if(!isJustified)
{
TextJustifyUtils.run(txtView);
isJustified = true;
}
return true;
}
});
}
Comparison
HTML formatting will cause you to have expected results.
bluejamesbond
fscz
shayanpourvatan