I am facing a simple problem. I am increasing textSize in xml. As I increase textSize there is some extra padding coming all around the text. I don't want that.
Here is my code:
<TextView
android:id="#+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="70sp"
android:gravity="bottom"
android:includeFontPadding="false"
android:lineSpacingExtra="0dp"
android:text="1"/>
How to remove that space inside the box?
try this it works quite fine in xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rizwan"
android:padding="#null"
android:includeFontPadding="false"
/>
if you want it in java it will be like this
youtextView.setIncludeFontPadding (false)
NOTE!: you can use negative padding or in points but its not recommended as this is the builtin boxModel padding of android
IF THAT DOES NOT WORK THEN as its stated in OFFICIAL DOC Each Font comes with own white spacing around
try using a custom font in the asset folder instead of default ROBOTO like its done in this awesome project here
Credit goes to #Sunilkushwah. he uses "HVD Fonts - BrandonText-Light.otf" and it do solves the problem
here is some code, I can replicate the bug even if I strip everything down to a simple TextView.
<TextView
android:layout_width="250dp"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:singleLine="true"
android:text="I AM VERY SMART I AM VERY SMART I AM VERY SMART"
android:textSize="16sp">
</TextView>
I wish I could post a screenshot but SE is not letting me. what happens is that the text is truncated in the middle (as intended) but with a single dot (.) rather than a full ellipsis (...)
it does this on all lollipop tablets that I own (nexus 7 and nexus 9). other devices are displaying the ellipsis properly. I have researched the issue and found various comments about people getting the same problem, but no answers.
I have the same problem as same as you.
I achieved my goal by setting:
width="85dp"
maxWidth="85dp" // same as above
maxLines="1"
Try this:
<TextView
android:layout_width="250dp"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:singleLine="true"
abdroid:focusable="true"
android:focusableInTouchMode="true"
android:text="I AM VERY SMART I AM VERY SMART I AM VERY SMART"
android:textSize="16sp">
</TextView>
I have a textview that should show a maximum of 5 lines and wrap the text. It should also show an ellipsis if the text is too long. The following works using Android 4.1 but not on 2.3. If I set scrollHorizontally to false, I only get 2 lines. Is there anything I can do to get the same result under 4.1?
<TextView
android:id="#+id/tvDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/ivIcon"
android:layout_toRightOf="#id/ivIcon"
android:layout_marginTop="-5dp"
android:ellipsize="end"
android:maxLines="5"
android:scrollHorizontally="true"
android:textColor="#000000"
android:textSize="16sp" />
Seems to be a known bug. Here's one solution I came across:
https://stackoverflow.com/a/6763689/753632
But that's over 2 years old. Not sure if someone came up with a better solution.
You must try android:Lines in place of android.maxLines
I'm currently testing an app on Android 4.0 Ice Cream Sandwich before releasing an update to the market. During the tests I realized that the ellipsize attribute stopped working.
I used it on a list view to truncate item titles which were to long. On Android 2.3.7 everything renders as expected. Titles that are too long get truncated and three dots are append to the end of the string. On Android 4.0 the title gets just truncated after the last word that fits completely on the screen, the rest gets skipped.
I've testes it on a Android 2.3.7 and a Android 4.0.3 phone. This behavior can even be tested in eclipse by changing the Android version in the Graphical Layout editor.
Does anyone has the same problem. Any work a rounds for this?
android:singleLine="true" works for me.
enter code here <TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:lines="1"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textColor="#ff4500"
android:text="Om Namah Shivaya : Om Namah Shivaya : Om Namah Shivaya : Om Namah Shivaya : Om Namah Shivaya" android:layout_marginTop="2dp">
<requestFocus
android:duplicateParentState="true"
android:focusable="true"
android:focusableInTouchMode="true" />
I can recall I had a similar issue and I could resolve it by setting the TextView(which had ellipsize attribute) gravity to left. But most probably this is another issue.
I'm using a TextView in Android, what I want to show 1 line in TextView ending with ". " but this give [] type box at the end. I don't know why? I just want to remvoe this box and only to show text ending with "... "
Update code for the list_row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="85dp"
android:orientation="horizontal"
android:gravity="center_vertical"
android:cacheColorHint="#4C7B8D"
android:background="#4C7B8D">
<ImageView
android:id="#+id/videoListImage"
android:src="#drawable/audio_thumbnail60x60"
android:layout_height="75dp"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:scaleType="fitXY"
android:layout_width="75dp"
android:padding="4dp"
android:background="#color/light_gray" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginRight="5dp"
android:layout_toLeftOf="#+id/next_arrow"
android:orientation="vertical"
android:gravity="center_vertical"
android:paddingLeft = "5dp">
<TextView
android:id="#+id/row_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="#color/app_background_color"
android:textSize="18sp"
android:ellipsize="end"
android:maxLines="1" />
<TextView
android:id="#+id/row_dis"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="#color/color_black"
android:layout_marginRight="2dp"
android:textSize="15sp"
android:ellipsize="end"
android:maxLines="1" />
<TextView
android:text="$7.50"
android:id="#+id/audio_price_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16dp"
android:textColor="#color/color_white"
android:textStyle = "bold"
android:paddingLeft = "12dp"
android:paddingRight = "12dp"
android:background="#drawable/blue_round_cornor_background" />
</LinearLayout>
<ImageView
android:id="#+id/next_arrow"
android:src="#drawable/next_arrow"
android:layout_toLeftOf="#+id/saved_purchased"
android:scaleType="fitXY"
android:layout_height="25dp"
android:layout_width="18dp"
android:layout_centerVertical="true"
android:visibility = "gone"/>
<ImageView
android:id="#+id/saved_purchased"
android:layout_alignParentRight="true"
android:layout_alignParentTop ="true"
android:scaleType="fitXY"
android:layout_height="25dp"
android:layout_width="25dp"
android:layout_marginRight="2dp"/>
</RelativeLayout>
Here is the images of "next_arrow"
Here is the code I am using the getView() in adapter.
String discription = listData.getDescription();
if (discription != null && discription.length() > 0) {
if (textViewDis != null) {
textViewDis.setTypeface(titleFont);
Log.e("data", ""+discription);
discription.replaceAll("\r\n", "");
textViewDis.setText(discription);
}
}
Here is the actual String of description to be display.
Andrew and Stephanie Tidwell candidly share their success story in this business. This story will help everyone listening realize that no one is perfect, even in a second generation business. This is a streaming audio file.
Still have some issue? I can update question more.
Quoting myself from one of my books:
Android's TextView class has the built-in ability to "ellipsize" text,
truncating it and adding an ellipsis if the text is longer than the available
space. You can use this via the android:ellipsize attribute, for example.
This works fairly well, at least for single-line text.
The ellipsis that Android uses is not three periods. Rather it uses an actual
ellipsis character, where the three dots are contained in a single glyph.
Hence, any font that you use that you also use the "ellipsizing" feature will
need the ellipsis glyph.
Beyond that, though, Android pads out the string that gets rendered on-screen, such that the length (in characters) is the same before and after
"ellipsizing". To make this work, Android replaces one character with the
ellipsis, and replaces all other removed characters with the Unicode
character 'ZERO WIDTH NO-BREAK SPACE' (U+FEFF). This means the
"extra" characters after the ellipsis do not take up any visible space on
screen, yet they can be part of the string.
However, this means any custom fonts you use for TextView widgets that
you use with android:ellipsize must also support this special Unicode
character. Not all fonts do, and you will get artifacts in the on-screen
representation of your shortened strings if your font lacks this character
(e.g., rogue X's appear at the end of the line).
I have bumped into the same problem when was trying to use custom "MetaPro-Medium.otf" as font for TextView with a
android:singleLine="true".
The box at the end of the string was really annoying.
I found no way how to solve this problem in Android, but at the same time found following work around.
I have installed "FontLab Studio v5.04"
Opened my font
Selected one of symbols I was not going to use
Menu->Glyph->Rename Glyph
Changed the name and unicode index from it`s original value to "FEFF" (Thank CommonsWare)
Double click on selected symbol and then remove all lines this symbol was created from.
Menu->File->Generate Font->save as type otf
As a result I got updated font and problem gone away.
Arslan, your layout is working fine in my case, I have tested the same with:
<TextView
android:id="#+id/row_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="18sp"
android:ellipsize="end"
android:maxLines="1"
android:text="This is the demo testing demo testing This is the demo testing demo testing"/>
... and getting the exact output as you want "one line ended with ..." and box should be removed. So I think there may be a something wrong with any character or text you are setting.
I face the same issue (show boxes([])) for some special symbols when I try to show content which is coming from webservice url even, I don't use android:ellipsize. then I replace code from
textview.settext(content);
to
textview.settext(Html.fromHtml(content));
working fine.
Actually I was running into this issue and instead of changing the font or using setText I just added scrollHorizontally as false and it fixed the extra box character
android:singleLine="true"
android:scrollHorizontally="false"
android:ellipsize="end"
There was a similar problem which i was facing in my project where in i was using a font type for the text view. few font types have these problem of making the ... appear as [] at the last. The problem would be solved if u try changing the font.