Code Monkey home page Code Monkey logo

justifiedtextview's Introduction

JustifiedTextView

Maven Central Android Arsenal

JustifiedTextView is an Android View that justifies the Text! 🙌🏻

Android introduced in API level 26 the method setJustificationMode(int), which is meant to justify the text inside a TextView.

If your min API level is 26, I recommend TextView.setJustificationMode(int). But if you need to support older Android versions, JustifiedTextView is what you need 😉

alt landscape

alt portrait

Usage

You just have to add the view in your layout:

<com.codesgood.views.JustifiedTextView
        android:id="@+id/tv_justified_paragraph"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="@string/lorem_ipsum_extended"
        android:textColor="@android:color/black"
        android:textSize="15sp" />

And that's it! 🎉 the text contained in the JustifiedTextView will be justified. (In this example I used 15sp as textSize, but you can use a different textSize and it won't be a problem).

You can set the text programmatically as well 👍🏻, you can even use JustifiedTextView as a regular TextView in your java class (because it extends TextView) and the result would be the same justified text in your UI.

Here is an example:

TextView justifiedParagraph = findViewById(R.id.tv_justified_paragraph);
justifiedParagraph.setText(R.string.lorem_ipsum_extended);

Add JustifiedTextView to your project

JustifiedTextView is available on Maven Central. Please make sure you're using the latest version by checking here

Gradle:

implementation 'com.codesgood:justifiedtextview:1.1.0'

Maven:

<dependency>
    <groupId>com.codesgood</groupId>
    <artifactId>justifiedtextview</artifactId>
    <version>1.1.0</version>
</dependency>

Thanks

License

Copyright 2014 CodesGood

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

justifiedtextview's People

Contributors

amilcar-sr avatar aserrano-phun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

justifiedtextview's Issues

Not Justified all the way

Im having the problem that its not justified all the way to the end . screenshot
my XML :
<com.codesgood.views.JustifiedTextView android:id="@+id/standarddetail_content_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:fontFamily="@font/martelsans_light" android:lineSpacingMultiplier="0.8" android:layout_marginTop="5dp" android:textColor="@color/text" android:textSize="@dimen/textsize" />
code setting the Textview content ( textview is inflated programatically )
View inflatedLayout = inflater.inflate(R.layout.standard_details, null, false); sv.addView(inflatedLayout); JustifiedTextView content = inflatedLayout.findViewById(R.id.standarddetail_content_text); content.setText(1998 wurde das Gesetz zur Kontrolle und Transparenz (KonTraG) beschlossen, das zu Veränderungen im Aktiengesetz und Handelsgesetzbuch geführt hat. Die wichtigsten Änderungen das Risikomanagement betreffend waren die Einrichtung eines Überwachungssystems, um den Fortbestand der Gesellschaft zu sichern (AktG), die Überprüfung dieses Systems durch den Wirtschaftsprüfer (HGB) und die Erweiterung des Lagerberichts um einen Risikobericht (HGB). Diese Regelungen gelten vor allem für Aktiengesellschaften, es gibt jedoch auch Ausstrahlungswirkungenauf GmbHs. Den Risikobericht müssen zudem mittelgroße und große Kapitalgesellschaften sowie Konzerne erstellen. ); //one long line no linebreaks in my app i get this string form a resource file

screenshot_1545231342

Formatted string loses its html tags

This library works very well but it has 1 downside - the fact that I lose all formatting from my string ( bold, italic, spaces between paragraphs ).

JustifiedTextView textView1 = (JustifiedTextView) findViewById(R.id.textView_1); textView1.setText(StringHtmlUtils.fromHtml(getResources().getString(R.string.myText_1)));

<com.codesgood.views.JustifiedTextView android:id="@+id/textView_1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:textSize="16sp" />

Any idea?

issue with api 30

if lines are more than one line the application will become freeze

Support for Html.ImageGetter()

Your library seems to ignore "<!--img->" tags in justification, any ideas? I really like how simple your library is compared to other solutions and I would like to use it in my project.

StringIndexOutOfBoundsException

I got the issue when setText with Strings in HTML format. It works fine with oridinary Strings.

java.lang.StringIndexOutOfBoundsException: length=0; index=0 at com.codesgood.views.JustifiedTextView.onLayout(JustifiedTextView.java:90)

other language like arabic

Hi

amazing job and fantastic, i can justify text of other language such as Arabic but you can't change the font family, it support 100% with no problem with English but not my language for the family font. i did try @font/cairo with Arabic text nothing change yes it justify the text but won't change the family font .

so two issue , 1- It justified the text of Arabic but you can't change fmailyfont
2- I still see blank space on the between of words

however I did use typeface but still face problem

TextView tex= findViewById(R.id.tex);
Typeface face = Typeface.createFromAsset(getAssets(), "@font/cairo .ttf");

tex.setTypeface(face);

thank you amazing job help me alot !

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.