Justified Text with central alignment in android - android

Hello everyone, i am working on android application in which i am showing some text using TextView with central alignment on the screen. But the problem is that the text is not properly justified on the screen. This is the xml code which i am using for showing text with central alignment on the screen. Please help me for doing this.
<TextView
android:id="#+id/lastMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_gravity="center"
android:text="Mana addd asdwd ekff fec greq crrq grooe cieurnf covhrpw cjcneie ejducbc ueiche deidhe idhcecm ekwp ww"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="12sp" />

This library will provide you a way to justify text.
Compatible for Android 2.2 to 5.X
https://github.com/bluejamesbond/TextJustify-Android

If you want to center align text, use android:gravity="center" as follows:
<TextView
android:id="#+id/lastMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_gravity="center"
android:gravity="center"
android:text="Mana addd asdwd ekff fec greq crrq grooe cieurnf covhrpw cjcneie ejducbc ueiche deidhe idhcecm ekwp ww"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="12sp" />

Related

Android TextView unwanted padding issue

I am having issue with android TextView. having unwanted spacein TextView,
the space is coming only sometimes. For your reference attached image above, you can see some extra space on the right end of TextView. Please help me guys.
here is the xml code
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="all"
android:ellipsize="end"
android:padding="0dp"
android:gravity="start"
android:text="#{message.message}"
android:textColor="#android:color/white"
android:textColorLink="#android:color/white"
android:textIsSelectable="true"
android:textSize="14sp"
tools:text="this is the problem i am having please helpme to find a solution" />
you can use this library to justify textview
https://github.com/navabi/JustifiedTextView
<ir.noghteh.JustifiedTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:padding="25dp"
xmlns:noghteh="http://noghteh.ir"
noghteh:text="text here"
noghteh:textColor="#color/text"
noghteh:textSize="18sp"/>

How to make TextView in Android wrap and adjust text beautifully?

When text is small then I get this:
But when text is big I get this:
Is it possible that text adjust itself by maybe better using spaces or decreasing little size automatically?
This is my TextView xml:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/seaGreen"
android:gravity="center_vertical"
android:padding="10dp"
android:textColor="#color/white"
android:textSize="35sp" />
For that you need to use external library for that, else you can set gravity as center
Library :
https://github.com/grantland/android-autofittextview
For Text Justify
https://github.com/bluejamesbond/TextJustify-Android
https://github.com/programingjd/justified
OR
you can check this answer
this work for me:
<TextView
android:id="#+id/your_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:textAlignment="center"
android:gravity="center"
android:padding="5dp"
android:text=""
android:textSize="14sp"/>

Padding in android, untidy my layout

I have this layout inside a linerar layout (It is a custom Dialog), and when i add padding in the buttons, my layout become untidy.
<RadioGroup
android:id="#+id/toggleGroupEntrega"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ToggleButton
android:id="#+id/toggleButtonEntregaOK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#color/bgOff"
android:checked="false"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="#string/entrega_ok"
android:textOff="#string/entrega_ok"
android:textOn="#string/entrega_ok" />
<ToggleButton
android:id="#+id/toggleButtonEntregaRecusa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#color/bgOff"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="#string/entrega_recusa"
android:textOff="#string/entrega_recusa"
android:textOn="#string/entrega_recusa" />
<ToggleButton
android:layout_margin="5dp"
android:id="#+id/toggleButtonEntregaAvaria"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/bgOff"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="#string/entrega_avaria"
android:textOff="#string/entrega_avaria"
android:textOn="#string/entrega_avaria" />
</RadioGroup>
that are the result:
if i remove android:paddingLeft="5dp" and android:paddingRight="5dp", works well, but i really wanna a padding inside the elements(I do not want the text along the edges).
Why it happens? (have alot of free space if you see compelte image)
i wanna that way, but with a lite bit more padding (in this case, have only 2dp):
Issue here is not padding, the issue here is that when you adding it last ToggleButton doesn't fit first line, and when it goest to the next one this happens. So as Der Golem said :
Try using proper casing. Or a smaller font size
The other thing, you can add
android:singleLine="true"
android:ellipsize="end"
to your last item, that way you can undestand what causes the issue in your case
EDIT : with following layout you can't reach your goal(unfortunetly)

Android: Need Ellipsis for Multiple TextViews in Relative Layout

I am new to Android, i have below task.
I want to align three TextViews adjacent to each other with ellipsis if the text is too long . Currently i am using below code which aligns my TextView adjacent to each other, but my problem is if the text is too long, the below code not putting the ellipsis. i got some trick to use both toleftof and torightof from here, but in my case it going to circular dependency as mentioned here.
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="#+id/reminderText">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/noteTagOne"
android:ellipsize="end"
android:singleLine="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/noteTagTwo"
android:ellipsize="end"
android:singleLine="true"
android:layout_toRightOf="#+id/noteTagOne"
android:layout_marginLeft="5sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/noteTagThree"
android:layout_toRightOf="#+id/noteTagTwo"
android:ellipsize="end"
android:singleLine="true"
android:layout_marginLeft="5sp"/>
</RelativeLayout>
I want output as,
Tag1... Tag2... Tag3...
Basically, i want some ideas, whether in xml i can achieve this or need to do it programmatically, since TextView text's are dynamic i cannot fix maxLength, sometimes only single tag may exist, at that time it should take full text.
Note: I am developing Android project using C# in Xamarin.
Added code is for the above highlighted part. I fixed overlapping of tagsicon & text. Now only two issues.
1) Last tag is overlapping with right aligned image.
2) If TextView texts are short, gap is shown in-between the tags
How to fix it?
try this solution
<LinearLayout 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:orientation="horizontal"
tools:context=".MainActivity" >
<TextView
android:id="#+id/noteTagOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxWidth="100dp"
android:singleLine="true"
android:text="Tag111111111111111111"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/noteTagTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5sp"
android:layout_toRightOf="#+id/noteTagOne"
android:ellipsize="end"
android:maxWidth="100dp"
android:singleLine="true"
android:text="Tag2222222222222222"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/noteTagThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5sp"
android:layout_toRightOf="#+id/noteTagTwo"
android:ellipsize="end"
android:maxWidth="100dp"
android:singleLine="true"
android:text="Tag3333333333333333"
android:textAppearance="?android:attr/textAppearanceLarge" />
Use this android:ellipsize="marquee" it will work
android:ellipsize="marquee"
or
android:ellipsize="end"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"

Android Textview Italic and wrap_contents

I am using 3 italic textviews with different colors
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal" android:id="#+id/submittedBy" android:paddingTop="10dip">
<ImageView android:id="#+id/subByImg"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="left" android:layout_gravity="bottom" android:src="#drawable/submitted_by_arrow"/>
<TextView android:id="#+id/submitLabel"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="left" android:text="Submitted by" android:textStyle="italic"
android:textSize="12sp" android:textColor="#color/gray" android:paddingLeft="5dip"/>
<TextView android:id="#+id/submitName" android:textStyle="italic"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="12sp" android:textColor="#color/maroon_dark" android:paddingLeft="10dip"/>
<TextView android:id="#+id/submitByDate" android:textStyle="italic"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="left"
android:textSize="12sp" android:textColor="#color/gray" android:paddingLeft="10dip"/>
</LinearLayout>
I wonder every last character is not displaying properly specially name displayed in the middle is "Dan Buckland" and it it is missing last character looks like "Dan Bucklano"
Also tell me pls how can have textview italic and bold both..
alt text http://www.freeimagehosting.net/uploads/953d573113.jpg
I had the exact same problem. I got around it by simply adding a space to the end of any string that needs to be in italics.
It may not be the most long-term-correct solution but it worked for me.
Seems like the bounding box is not correctly calculated when using italic.
Have you tried to use paddingLeft=6 and paddingRight=6 for the elements?
(less chance of overlap).
For multiple styles in a TextView see Is it possible to have multiple styles inside a TextView?
You can use   with the text in string.xml file.

Categories

Resources