0

I'm trying to make an app that involves writing some poems in Arabic language, however I'm having difficulties in making the poem look justified to look nice when reading them.

I'm using TableLayout to fill in the poem:

<TableLayout
        android:id="@+id/whole_line_table"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:gravity="center_vertical"
        android:stretchColumns="1"
        >
        <TableRow
            android:padding="6dp">
            <TextView
                android:layout_width="0dp"
                android:id="@+id/poem2_textView"
                android:layout_weight="1"
                android:gravity="right"
                android:textSize="15sp"
                tools:text="Some text here"
                />

            <TextView
                android:id="@+id/poem1_textView"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:gravity="right"
                android:textSize="15sp"
                tools:text="Some text here"
                android:maxLines="1"/>
        </TableRow>
    </TableLayout>

Example of how I want the poem to appear in the image below

verse example

You can see how each verse in the poem start and end together and notice the space between them.

Screen shot of what I have in layout so far shown below enter image description here

I want the right part to reach to end not half the textView only.

I'm totally new to developing apps so please excuse me for any bad coding look

Omar
  • 61
  • 1
  • 6

1 Answers1

0

set text width to fill the parent and set margin to element. use gravity center.

       <TextView
        android:id="@+id/poem1_textView"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:textSize="15sp"
        android:margin="18dp"    
        tools:text="Some text here"
        />

that could help you to simulate an justified text, if you want a better fix or if you are using android 8.0. it supports justification on texts. Look at this answer and try those libraries. Android TextView Justify Text

I Hope it helps.

Bonestack
  • 81
  • 6
  • I Don't think match_parent will work, because I want the screen to be evenly divided so that I can write one verse in each line such that: Some text here Some text here Some text here Some text here Some text here Some text here above is what Im looking for. I can't simply set margin to 18. I don't really know how much work will be there. what Im really looking for is for a way to resize the text to fit it if its big for the boundary of the textView or to be stretched if there is not many word so that the poem over all will look cool. – Omar Jul 01 '18 at 20:21
  • Open the link I left you. there is a library for that. – Bonestack Jul 01 '18 at 20:55
  • You could also use line jump inside the string and where you need it. "\n" – Bonestack Jul 01 '18 at 20:56
  • Problem with library, it does not support the version Im working on. I don't want to use jump because Im writing each verse in its own TextView. – Omar Jul 01 '18 at 21:00
  • how will your app recognize each verse ? I mean if you have your poem in a string, how would you say to app, which is a verse, and which is another one ? – Bonestack Jul 01 '18 at 23:26
  • Try this Custom TextView https://stackoverflow.com/questions/44368339/justifying-text-inside-a-textview-in-android – Bonestack Jul 01 '18 at 23:28
  • Im putting all verses in a table so each row will have a new verse and each row has two columns to put each part of a verse in it. – Omar Jul 02 '18 at 12:50