TextView with gravity=center and ellipsize=marquee? - android

I have a TextView with possibly very long text. Also the text should be centered when it is short enough to not cause the marquee effect.
This is the layout xml:
<TextView
android:id="#+id/TextView01"
android:layout_height="wrap_content"
android:textColor="#000000"
android:gravity="center"
android:textSize="12dp"
android:layout_width="fill_parent"
android:focusable="false" android:lines="1"
android:marqueeRepeatLimit="marquee_forever"
android:focusableInTouchMode="false"
android:ellipsize="marquee"
android:scrollHorizontally="true"></TextView>
also, I use findViewById(R.id.TextView01).setSelected(true) to immediately start the marquee.
When the text becomes too long and the marquee effect would kick in it just disappears. Short text is displayed and works.
When I remove the android:gravity="center" the text is visible and marquee works. But short text will no longer be centered in the TextView. What am I doing wrong?
Edit: I'm using Android 2.2.
Edit2: When I replace android:lines="1" with the (deprecated) android:singleLine="true" everything works as expected, but this does not seem to be an ideal solution.

Try to change the attribute android:line="1" to android:singleLine="True". It works fine for me.

Change the android:lines="1" attribute to android:inputType="text". Seems like a bug though.

Related

Android TextView SingleLine field hides long text

I have a TextView which sits on the left side of the screen and is set with gravity="right" and it is set with SingleLine = "true."
If by some chance the text in this view gets too long I want it to simply disappear off the left hand side of the view. I thought the configuration below would do that but what actually happens is the the long string disappears completely, presumably down and outside of the view somewhere.
How can I create a simple text view that contains a single line of text and keeps its layout even when something unexpected happens? ... or even something predictable.
<TextView
android:id="#+id/tempF"
android:text="#string/tempF"
android:layout_width="146dp"
android:layout_height="wrap_content"
android:textColor="#cccccc"
android:textStyle="bold"
android:textSize="92dp"
android:fontFamily="serif"
android:gravity="right"
android:layout_marginTop="60dp"
android:layout_gravity="top|left"
android:singleLine="true"
/>
This is the purpose of "ellipsize" - truncating a portion of text to indicate additional text.
In you case, you may simply need to add something like:
android:ellipsize="end"
or you might need to go deeper:
Automatically ellipsize a string in Java
Or look at this:
android ellipsize multiline textview
The idea behind extending the class is that you can customize the behavior of the TextView when the text content exceeds the space provided. For example, you can give it the appearance the it "bleeds over" by removing padding, etc. An ellipsis is an indicator that is commonly used to explain "there's more text that you can't see" - this is how it would look:
This is really a really long...
(the 3 periods are the ellipsis - your text goes the opposite direction, but it should still work)
With a custom TextView, you could change the "..." to nothing or anything else you want (even an image, which I've done).
You could also marquee the text:
TextView Marquee not working
Add 2 properties in xml
android:singleLine="true"
android:ellipsize="end"
You should play with ellipsize attribute of the TextView.Check below:
<TextView
android:id="#+id/tempF"
android:text="#string/tempF"
android:layout_width="146dp"
android:layout_height="wrap_content"
android:textColor="#cccccc"
android:textStyle="bold"
android:textSize="92dp"
android:fontFamily="serif"
android:gravity="right"
android:layout_marginTop="60dp"
android:layout_gravity="top|left"
android:singleLine="true"
android:ellipsize="end"
/>
<TextView
android:id="#+id/tv_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/colorGray"
android:textSize="#dimen/_18dp"
android:padding="#dimen/_2dp"
android:singleLine="true"
android:ellipsize="end"
android:text="#string/desc" />
Since android:singleLine is deprecated. We can use this line android:maxLines
Can do like this.
android:ellipsize="end"
android:maxLines="1"
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#000000" />
It works.

TextView's ellipsize not working on maxLines = 1

I really cannot figure out why, but I am only able to get ellipsize working on maxLines=2 and more. I am displaying a few words of description and then a long string with no spaces.
This is how the TextView looks like:
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#757575"
android:text="#string/gcm_not_registered"
android:maxLines="1"
android:ellipsize="end"
android:id="#+id/login_gcmRegistrationTextView"/>
I then programatically set a text to it, but depending on the maxLines limitation, I get two different results:
The only thing that changed was the maxLines, why isn't the line filled in the first picture as well?
There are two ways to fix it:
Try to change android:ellipsize="end" attribute to android:ellipsize="marquee".
Try to remove android:maxLines="1" android:ellipsize="end" attributes and add android:singleLine="true" attribute.
This code works for me:
In the xml add:
Attribute ellipsize: marquee
Attribute lines: 1
In java:
<yourTextView>.setHorizontallyScrolling(true);
<yourTextView>.setSelected(true);
If there is another item that request the "focus" you lose the marquee effect. The textView need the state selected to prevent this.
Actually the problem is with the spannable text, if you set spannable text this wouldn't work. Other than this below code works for me
<TextView
android:id="#+id/tv_second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40dp"
android:layout_margin="5dp"
android:padding="5dp"
android:fontFamily="sans-serif-condensed"
android:textColor="#b3277b"
android:background="#f7ecff"
android:layout_below="#id/tv"
android:text="This is first line\nThis is second line\nThis is third line"
android:ellipsize="end"
android:maxLines="2"
/>

TextView Marquee not showing '..'

I already tryed alot of solutions, maxLine, maxLenght, marqueeAlwaysShowing, the ellipsize with marquee..the focusable thing.. I can't can't just get it working.
I erased all the additional XML to make it working and here it is, this is what I have:
<LinearLayout
android:id="#+id/promptDefine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/counterDefinitionName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:clickable="true"
android:onClick="nameCounting"
android:text="#string/nameIt"
android:textColor="#color/count_item_to_be_defined"
/>
</LinearLayout>
So, what should I have to add it at textview to limit text to 10 characters ? but if they are more just insert the "..." at the end. I already tryed some things like:
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
And didn't work, thanks in advance!
EDIT:
Maybe its the Clickable feature attribute that is messing this ?
The three dot only shows when the textView doesn't have enough space for the characters.
in your case just set a fix width and set single line. then it should work.
<TextView android:id="#+id/counterDefinitionName"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:clickable="true"
android:onClick="nameCounting"
android:text="#string/nameIt"
android:singleLine="true"
android:textColor="#color/count_item_to_be_defined" />
not "clickable", make it "selected"

How to fade edge of TextView in Android?

I am working on Android 3.0.
I have a TextView on my layout and I want it to be faded after 8 characters like in the main menu. This Text is located in RelativeLayout.
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_name"
android:textStyle="bold"
android:textColor="#color/white"
android:maxWidth="50dp"
android:maxLength="8"
android:layout_below="#+id/item_frame"
android:layout_alignBottom="#+id/item_view"
android:layout_centerHorizontal="true"
android:fadingEdge="horizontal">
</TextView>
Does anyone has an idea how to fade the text after few characters?
I think you need to combine fadingEdge with ellipsize and singleLine, and even then it will only happen if the text is longer than the control's width.

Running string in Android

I'm not sure, if "running string" the right name.
I try to explain, what I mean.
I have a TextView in my Layout and want to have text there, which runs from rigth to left, again, and again, and again.
I thougt, I just should enable marquee for that, but the text stays instead of running :(
Here is my TextView-Code:
<TextView
android:id="#+id/text_ticker"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/grey0"
android:textColor="#color/black"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:padding="10dp"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true">
</TextView>
Thank you,
Mur
Ellipsize marquee scrolling will only scroll when the textView gains focus.
Edit:
Here is the solution

Categories

Resources