Giter Site home page Giter Site logo

textjustify-android's Introduction

Logo

Simple Android Full Justification Overview

This is very simple. What you want to do is get the library itself and add it to your Android project. Upcoming

  1. Support for auto-hyphenating
  2. Support for editable text (while justification is enabled)
  3. More optimizations

Been very busy lately

Option 1 (Draw-Based) - Setup

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
}

Option 1 - Result

Comparison

Logo

Option 2 (String-Based) - Setup

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;
        }
        
    });
}

Option 2 - Result

Comparison

Logo

Notes

HTML formatting will cause you to have expected results.

Contributors

bluejamesbond
fscz
shayanpourvatan

textjustify-android's People

Contributors

shayanpourvatan avatar luelue avatar

Watchers

James Cloos avatar Andrei Apanasik avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.