Android justifying android text
NickName:aali83 Ask DateTime:2013-08-13T00:38:31

Android justifying android text

I am trying to make sure that the hours are all justified (meaning they begin and end at the same margin) as you can see from Monday-Thursday they align properly. Friday and Saturday the 11:00 is not aligned properly with the rest. No doubt because of the 03:00 and 01:00 taking different amount of space. But is there a way to make them all align perfectly?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="@dimen/margin_3times"
    android:orientation="horizontal"
    android:weightSum="1"
     >
    <com.example.views.TextView
        android:id="@+id/openhour_day"
        android:layout_width="0px"
        android:layout_weight="0.9"
        android:layout_height="wrap_content"
        android:textColor="@color/gray_dark"
        android:textSize="@dimen/middle_text_size"
        android:text="Day"/>
    <com.example.views.TextView
        android:id="@+id/openhour_hour"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.1"
        android:singleLine="true"
        android:textColor="@color/gray_dark"
        android:textSize="@dimen/middle_text_size"
        android:text="Hour"/>

</LinearLayout>

hours unaligned

Copyright Notice:Content Author:「aali83」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/18192241/android-justifying-android-text

Answers
Nick 2013-08-12T16:52:18

You could use a monospaced font. Monospaced font use fixed width sizes for each character. Android has Droids Sans Mono that you can use.\n\n<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\"\n android:paddingTop=\"@dimen/margin_3times\"\n android:orientation=\"horizontal\"\n android:weightSum=\"1\"\n >\n <com.example.views.TextView\n android:id=\"@+id/openhour_day\"\n android:layout_width=\"0px\"\n android:layout_weight=\"0.9\"\n android:layout_height=\"wrap_content\"\n android:textColor=\"@color/gray_dark\"\n android:textSize=\"@dimen/middle_text_size\"\n android:typeface=\"monospace\"\n android:text=\"Day\"/>\n <com.example.views.TextView\n android:id=\"@+id/openhour_hour\"\n android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:layout_weight=\"0.1\"\n android:singleLine=\"true\"\n android:textColor=\"@color/gray_dark\"\n android:textSize=\"@dimen/middle_text_size\"\n android:typeface=\"monospace\"\n android:text=\"Hour\"/>\n\n</LinearLayout>\n",


Henrique 2013-08-12T16:43:03

Try the following:\n\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\"\n android:orientation=\"horizontal\"\n android:paddingTop=\"@dimen/margin_3times\" >\n\n <com.example.views.TextView\n android:id=\"@+id/openhour_day\"\n android:layout_width=\"0px\"\n android:layout_height=\"wrap_content\"\n android:layout_weight=\"1\"\n android:textColor=\"@color/gray_dark\"\n android:textSize=\"@dimen/middle_text_size\"\n android:text=\"Day\" />\n\n <com.example.views.TextView\n android:id=\"@+id/openhour_hour\"\n android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:layout_gravity=\"left\"\n android:layout_weight=\"2\"\n android:textColor=\"@color/gray_dark\"\n android:textSize=\"@dimen/middle_text_size\"\n android:singleLine=\"true\"\n android:text=\"Hour\" />\n\n</LinearLayout>\n",


More about “Android justifying android text” related questions

Android justifying android text

I am trying to make sure that the hours are all justified (meaning they begin and end at the same margin) as you can see from Monday-Thursday they align properly. Friday and Saturday the 11:00 is not

Show Detail

Justifying text inside a TextView in android

So, as most of you know, there is no text justifying inside a TextView in Android. So, I built a custom TextView to get around the problem. However, for some reason, sometimes punctuation marks bre...

Show Detail

Android O Text Justification Hebrew

I know there has been A LOT of talk here regarding justifying text in Android. But Android O just came out and a new feature came out with it, Text Justification. They say use the final

Show Detail

Justifying text in Android without using a WebView

Is it possible to justify the content in Android without using a WebView? What I have come across after searching is that Android does not support full text-justification and it can be done only t...

Show Detail

Android: Justify text to the right in nested Linear Layout

I am having a very hard time justifying TextViews to the left in Android. I looked here but did not have success. The TextViews I want to justify are in Linear Layouts nested in a parent Linear Lay...

Show Detail

Justifying text in the indexes of an array

If you have the given array, how would you go about justifying the text for a given space? Lets say you need 20 characters including white spaces in every index. Example array ['Hello there champ...

Show Detail

Justifying database texts on android

I'm working on story application pjoject for android. The story text is in the database/db file. I used textView and the text is working good on the application but it's not justified. Is there a w...

Show Detail

Justifying text in Android

I need to justify some text (RTL), which is a string (S1) from the server. But a TextView can't justify text, so I have to use a WebView, now I have to create a HTML file in which will display S1. ...

Show Detail

justifying text in two columns with display: flex

What's the best way to position items in two columns, each of which has display:flex? I'm coming across the problem that when the text wraps everything below it moves out of alignment. I'm fairly s...

Show Detail

Justifying Android EditText using JUSTIFICATION_MODE_INTER_WORD

I have an EditText in my app. I tried to use JUSTIFICATION_MODE_INTER_WORD (https://developer.android.com/reference/android/text/Layout#JUSTIFICATION_MODE_INTER_WORD) To make it's text justified: e...

Show Detail