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.
Related
I've set a TextView as the display. I want to display the operation being performed in one line, for example:
9856243187 + 2457896123 - 214583
The problem is, when the input reaches the edge of the TextView - it jumps to the next line.
So, is there anyway to avoid this behavior and keep the input in one line, even if it goes out of the screen?
You should use android:maxLines="1" in your TextView tag.
android:singleLine="true" is deprecated.
android:singleLine="true"
is the answer
Update :
android:singleLine attribute has been deprecated since API Level 3, you can use
android:maxLines="1"
tl;dr:
For new users seeing this question, use android:singleLine="true". Ignore deprecation warnings.
Explanation
According to this bug report, setting android:maxLines="1" may cause your application to crash when some specific values are set in android:ellipsize as well. Apparently it affects most Android devices running 4.1 Jellybean through 6.0.1 Marshmallow (being fixed in 7.0 Nougat). Depending on your device, your mileage may vary. However, if you as a developer are targeting a wide range of devices, it is best to use android:singleLine="true" in order to prevent crashes.
add the code in your Textview
android:singleLine="true"
Thanks guys single line did the tricks but i also had to remove the ellipsis:
android:ellipsize="none"
This code worked for me:
android:singleLine="true"
If you want to manually scroll your single line content then you should use TextView inside HorizontalScrollView
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Single line text view that scrolls automatically if the text is too long to fit in the widget" />
</HorizontalScrollView>
Set the TextView to singeline.
Take a look at this
Can you please try this one ?
<TextView
android:text="Single line text view that scrolls automatically if the text is too long to fit in the widget"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
Hope this will help you.
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 some RTL text (Hebrew) that I want to be aligned right inside the TextView. Currently the XML looks like this:
<TextView
android:id="#+id/textView2"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="right"
android:paddingRight="10dp"
android:singleLine="false"
android:textColor="#FFFFFF"
android:textDirection="rtl"
android:textSize="12sp"
android:textStyle="bold" />
And it acually works great on Galaxy S3 Android 4.2.2 and I even tested it on a Galaxy S1 Android 2.3.3 and it was ok too. But on some devices, for example Galaxy S2 Android 2.3.5, it's aligned left for some reason.
I searched alot and I did not find and solution to this problem, I'd be happy if someone will show me a solution within the XML layout file, but programatcly solution can work as well.
I tired with your code.. you want to placed the text in right side of textview right?...
I'm pretty to help you because, I also gone through this issue..
In your code,
android:gravity="right"
Instead of this, try this
android:gravity="end"
I think this is what you are looking for
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 am currently developing an app and just ran some testing on ice cream sandwich and noticed some odd behavior when using the property android:ellipsize="end" in a textview. it is adding a [ character after the dots. This bug is driving me nuts and only appearing in ice cream sandwich. I saw a previous thread about this, but none of the fixes there helped. Any ideas, but report for android 4.0, maybe? My code below incase I am wronging ice cream sandwich somehow.
<LinearLayout
android:id="#+id/mainTitleLayout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="0.36"
android:orientation="horizontal"
android:weightSum="1" >
<TextView
android:id="#+id/mainTitle"
android:layout_width="135dp"
android:layout_height="wrap_content"
android:layout_marginLeft="62dp"
android:layout_marginTop="4dp"
android:layout_weight="0.53"
android:editable="false"
android:ellipsize="end"
android:gravity="center_vertical|center_horizontal"
android:singleLine="true"
android:textColor="#fff"
android:textSize="26sp"
android:textStyle="bold"
android:width="125dp" >
</TextView>
</LinearLayout>
I set the text dynamically in code via
TextView title = (TextView) act.findViewById(R.id.mainTitle);
title.setTypeface(Utils.font);
title.setText(detailTitle);
I think I know your problem. I have discovered this problem with my custom font that I set via setTypeface. The answer is found in the source code for Layout, which handles the drawing of TextViews to the screen. Take a look at the method 'ellipsize' at ling 1668. It appears to use a character, the 0-width space (U+FEFF), in addition to the ellipsis character. My guess is that your custom font does not include the 0-width space character, this causing the box to render. I have the same problem! The fix would necessitate altering the .ttf or .otf file to include the 0-width space character. Hope this helps!
I had a similar problem using a custom font in a TextView, actually in 1.6. In my case, I replaced the standard TextView with the version in this link:
android ellipsize multiline textview
and the extra characters went away.
If I were you, I would try minLines and maxlines inside TextView declaration, this way:
android:minLines="1"
android:maxLines="1"
instead of android:singleLine="true". I had a similar problem, that emerged only when using android 4. I solved this way, but I didn't change the font via setTypeface.