TextView ellipsize and broken symbols [duplicate] - android

This question already has answers here:
android ellipsize multiline textview
(23 answers)
Closed 8 months ago.
I have some problem with standard android ellipsize mechanism.
My textview xml layout is next:
<TextView
android:id="#+id/something"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/message_test_text"
android:lines="2"
android:ellipsize="end"
android:textColor="#drawable/dialogs_text_selector"
/>
Then in code I'm setting Helvetica typeface to this field. And then, in the end of second line I see broken symbol after dots:
Because it used in list, I see a list of squares.
Can I remove it without tons of code?
Thank you!

There is a issue logged here. Many people have some or the other problem when using TextView with ellipsize in a ListView. There are many workarounds that suggest changing the textview to single line, but you cant use that.
Try setting the android:maxLines="2" attribute.
Update:
Use TextUtils.ellipsize API to manually ellipsize the string before setting it to the textview. See whether the ellipsized string returned by this API contains the square char at the end.
Usage sample code:
TextPaint tp = new TextPaint();
tp.setTextSize(float textSize);
tp.setTypeface(Typeface typeface);
Charsequence elipText;
elipText = TextUtils.ellipsize ( text, tp, avail, TextUtils.TruncateAt.END);
textview.setText(elipText);

The problem here I don't think it was your code. The problem is your .tff file which is missing the ellipsize character, hence the square is displayed. Your font was not... let's say mobile optimized.

Related

Android textview incorrect linebreaking

Below is some text from a textview (background is red for emphasis on the boundaries).
As you can see, the word "the" before "digital generation" should have been in the previous line since there was enough space. Is there any way to make TextView render it correctly?
I tried android:breakStrategy="high_quality" without luck.
Looks like adding android:breakStrategy="simple" solves it

Is there any way to ellipsize the hint in the EditText?

The length of hint in my EditText is bit longer than the width of ET view. So how can i set marquee attribute to ET view. I have tried setting it, but the app crashes giving the error : E/AndroidRuntime(2095): Caused by: java.lang.IllegalArgumentException: EditText cannot use the ellipsize mode TextUtils.TruncateAt.MARQUEE
I have gone through the docs of ellipsize method, but not getting what i am supposed to do.I have tried these two steps :
1)
android:maxLines="1"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
2) android:maxLines="1"
android:scrollHorizontally="true"
Docs of ellipsize method:
Causes words in the text that are longer than the view is wide to be ellipsized instead of broken in the middle. You may also want to setSingleLine() or setHorizontallyScrolling(boolean) to constrain the text to a single line. Use null to turn off ellipsizing. If setMaxLines(int) has been used to set two or more lines, only END and MARQUEE are supported (other ellipsizing types will not do anything).
Let me know what modification has to be done so that it works right.Thank you
I think marquee doesn't works for EditText.You can use other attribute to ellipsize hint if it is getting longer than the size of editText.
android:ellipsize="end"
#DJphy - I found a solution no need to set ellipsis. when you are setting the string to edit text just set simple HTML attributes to string.
Played with some HTML tricks and it worked for me.
ex:-
nameEdittxt.setHint(Html.fromHtml("<small><small><small>" + getString(R.string.enter_name) + "</small></small></small>"));
This will help to set hint smaller and Edit text size as normal you had set as fontsize.
Look at my attachments -
Before setting HTML attributes to hint -
After setting HTML attributes to hint -

Numbers and hebrew text cause unwanted new lines

For some unknown reason, if I put the following string:
15 קמ
in a text view, it results in a new line between the "15" and the "קמ":
15
קמ
If I replace the "קמ" with "km" then it works fine...
Note: this doesn't happen if both string's parts are Hebrew.
Any clues?
I think that hebrew is interpreted RTL (right to left) while the other part is LTR (left to right). Given this, the TextView has to represent something like this:
\LTR 15 \RTL קמ
My logical guess is that the TextView puts the RTL part on a new line to deal with the nonsense of having both parts on the same line. If you force it all the way RTL when the locale is hebrew, I think it would regulate the rendering and solve the issue. I would suggest you try adding the "RIGHT-TO-LEFT MARK" character \u200F at the beginning of the string:
String text="15 קמ";
if (hebrew) {
text="\u200F"+text;
}
Also, it seems that some fonts are showing a graphical interpretation of the special character (while it shouldn't). You will probably need to use this font to get rid of it.
I have also experienced TextView alignment issue when I'm working with alphanumeric + arabic text in same text view, they will realign all the texts in left to right order which results ridiculous output. This kind of language issue is not really something we can fix in direct approach.
What we did were separating out the texts to more text views if applicable, which in your case I would suggest separating out the value and Hebrew text into separate TextView.
Try to use UTF-8 encoding for hebrew text, for eg:
String text = "15 קמ";
text = new String(text.getBytes(), "UTF-8");
If your textview can fit in one line, I think I might have a solution. This is the xml layout that did the trick.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="none"
android:text="15 קמ"
android:maxLines="1"
android:padding="8dp"
android:singleLine="true" />

Android Textview setText doesn't show hebrew

In my application I have a text view that represents song title, which means it can be filled with titles in different languages. I'm having a strange problem :
When I do myTextView.setText("שלום") it won't show anything.
But if I do the same in the xml file (as text property) it does show the text ?
Found the problem, I had an attribute of android:singleLine="true" and it didn't work fine with hebrew
for me the problem was messing with line spacing -
textView.setLineSpacing(0,0);
just in case it will help someone

Android TextView won't show right number of lines in Android 2.3

I have a couple of TextViews in my app, which should have exactly 3 lines. This works on Android 3+, but on Android 2.3, which I'd also like to support, these fields have exactly 2 lines. I've also tried TextView.setLines(3); in code, but that does not seem to help. This is my TextView:
<TextView
d1p1:lines="3"
d1p1:maxLines="3"
d1p1:minLines="3"
d1p1:ellipsize="end"
d1p1:text="Some Text"
d1p1:textAppearance="?android:attr/textAppearanceMedium"
d1p1:layout_width="fill_parent"
d1p1:layout_height="55dp"
d1p1:id="#+id/detailsTextView"
d1p1:layout_below="#+id/locationTextView"
d1p1:textSize="13dp"
d1p1:textColor="#color/app_darkgray"
d1p1:background="#color/app_dark_background"
d1p1:layout_marginLeft="#dimen/sr_horizontal_padding"
d1p1:layout_marginRight="#dimen/sr_horizontal_padding" />
Setting the height to wrap_content also does not work.
After some research it looks like my suspicion is correct. As discussed here (ellipsize multiline textview), Ellipsize causes issues with the min/max lines attributes. Because of this you may want to consider avoiding the Ellipsize otherwise, if that is not an option, you can follow the instructions in the other thread to use a custom TextView class to work around the problem.

Categories

Resources