I am trying to do the right to left text direction, but I am getting unexpected result (not like the one when I do html css). Here is the code I have for that textview:
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="96dp"
android:gravity="right"
android:text="#string/welcomeMsg"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textDirection="rtl"
android:textSize="#dimen/welcomeMsgSize" />
I believe I did everything there is to do. Maybe I forgot something or don't know it. I am pretty new to android. The picture shows the output of the above The problem here is the whitespace preceding the text inside the textview and post the text too. Thanks for your help in advance :)
You should change Textview gravity from "Center" to "Right" or "Left" Depending on your need.
Gravity will set gravity to your text so change it. And also change the text alignment from center to right or left.
android:textSize="#dimen/welcomeMsgSize" there lies the culprit.. reduce the size you specified in that file there..!!
Related
I have a TextView with a height depending on previous content, but there might be a long Text in it. How can I cut it off at the right point and concatenate three dots or something similar to the new end?
Currently it looks like this:
I found some solutions for Single Line Text, but how does it work with more than one line? I also do not know the number of lines, because this depends on the screen size.
Are there other typical ways on Android to show that the text can be extended? E.g. a colour gradient in the last line?
Edit:
When I do it without a fixed heigth, I have to make the height depend on the element above and my XML will look like this:
<TextView
android:id="#+id/podcastShortDesc"
android:text="Long text"
android:layout_below="#+id/podcastTitle"
android:layout_toRightOf="#+id/podcastLogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="3"
android:ellipsize="end"
android:layout_above="#+id/podcastMoreAction" />
When I do specify maxLines I can have luck an it will work:
But if the title is too big, it does not work:
You should add following code for "3 dots" at the end.
android:ellipsize="end"
You should remove fixed height property
android:layout_height="50dip"
instead you should add number of lines
android:maxLines="4"
android:layout_height="wrap_content"
Android will take care everything else. In this way, even if text is smaller than 4 lines, android will take care size. If it is more than 4 lines, it will add "3 dots" :) Specify fixed height may cut your text.
Try this. Hope it will work.
<TextView
android:id="#+id/podcastShortDesc"
android:text="LONG LONG LONG TEXT"
android:layout_width="match_parent"
android:layout_height="50dip"
android:maxHeight="50dp"
android:ellipsize="end"/>
I have tested 50dp can show two line in normal font size. So in 50dp height you should add maxLines 2.
Try this fix layout_height and add scroll in your textview
<TextView
android:id="#+id/text1"
android:layout_width="match_parent"
android:layout_height="50dip"
android:text="Hello......"
android:scrollbars="vertical"/>
I have a problem with my project. I use android.widget.Button. When word can not fit in one line in the Button then it cut it like this: Somelon>gword (where '>' is new line). How to fix it? And how to create inner padding for the text because the long word touches the button's borders?
You can try below code. Where paddingRight and paddingLeft keep padding of 25dp in right and left. If you want to text on in one line.Then
you can use android:singleLine="true"
<Button
android:id="#+id/she_was_good"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="25dp"
android:paddingLeft="25dp"
android:ellipsize=”marquee”
android:text="#string/im_sorry_lol_str" />
Read this post
Try using the property android:singleLine="true" and android:padding="10dp" to your button widget.
I give below attributes that I use textView in my application. ( Green text in middle )
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center_horizontal"
android:text="10/9"
android:id="#+id/estimate_fertility_date"
/>
However, there are spaces like the example picture. I want to set these spaces because when App initialize, It seems awful.
I have researched about 1 hour and I found some answers but They are not which I want answers.
https://stackoverflow.com/a/6864017/2834196
It 's not easy to get absolutely no text padding in a normal TextView. One way is to can set a minus margin for the TextView, or just use textview.setIncludeFontPadding(false) to reduce padding to some degree.
Adding negative values to margin does it help you?
<TextView
android:layout_marginTop="-10dp" />
I have read a few of the other threads here with similar concerns, but none of their answers seemed to work for me.
Can't get ellipsis to work on Android
Android: Something better than android:ellipsize="end" to add "..." to truncated long Strings?
I have a Relative Layout with 2 elements, a text view and an image view. I need the text view to be 1 line and to truncate about 5sp short of the image view and apply ellipsis to the end of the text.
<RelativeLayout
android:id="#+id/title_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5sp">
<TextView
android:id="#+id/"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize="10sp"
android:textColor="#FFFFFF"
android:text="title"
android:maxLines="1"
android:ellipsize="end"/>
<ImageView
android:id="#+id/"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="5sp"
android:layout_marginLeft="5sp"
android:background="#drawable/home"/>
</RelativeLayout>
In the above code, I was attempting to apply a margin left to the Image View to force the text view to its left to truncate by as many sp as I put in the margin.
The code above would truncate the text view to a single line and add (...) but only to the end of that line; irrespective of the ImageView to it's right, regardless of whatever margin I apply to it. The Image View appears above the text. I figured this may be due to them being in a relative layout.
Any help in figuring out how to make the text view respect the margin/space taken up by the image view would be greatly appreciated.
I believe what you want to do is to first place the image view (with margins) and then set the text to align to the left border and to be placed to the leftOf the image.
This should be easy but is just doesn't work...
I want to simply display the text of my textview on the right hand side instead of the left
<TextView android:id="#+id/PasswordConfText"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right"
android:layout_width="200sp"
android:text="Password Conformation:">
</TextView>
yet that doesn't change a thing. if I put right or left or center_horizontal...
what am I missing?
Thanks
Jason
put android:gravity="right" instead android:layout_gravity
Have you tried using gravity instead of layout_gravity?