Running string in Android - 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

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 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"

Horizontally Scrollable TextView show inconsistent behaviour across android versions

I have a text view that has a single lined Arabic (Right-to-Left) text. The Text content increases by time, and the last (left-most) part should always appear. The horizontal scroll bar is initially set to right, and auto scrolls to left as text increases.
The below code works great on a 2.3 Android phone.
This comes from the layout.xml
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="none"
android:fadingEdge="horizontal"
android:gravity="right"
android:scrollHorizontally="true"
android:scrollbars="horizontal"
android:singleLine="true"
android:text="#string/txt_start"
android:textAppearance="?android:attr/textAppearanceLarge" />
I have this in the onCreate() method of my Activity
tv = (TextView) findViewById(R.id.textView1);
tv.setMovementMethod(new ScrollingMovementMethod());
The problem is the inconsistent behaviour of the text view on phones having android 4.0+ . The horizontal scroll bar is initially no placed on the right, so the TextView is initially blanked! If I try to scroll the blank textView, the text shows up. When extra text is added, the scroll-bar is not scrolled to show the new text, but if I manually scrolled the text, it appears.
I searched stackoverflow, and tried to add the below properties with no success.
android:focusable="true"
android:focusableInTouchMode="true"
None of those solutions worked in my case where I wanted to animate scrolling of TextView with android:gravity="right". Simple workaround that helped though is to keep TextView gravity to left but place it aligned to right inside a RelativeLayout container:
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoScrollingTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="left"
android:singleLine="true"
android:ellipsize="none">
</RelativeLayout>
Try this example, it should work:
<?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="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/myText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/myscroll"
android:ellipsize="marquee"
android:singleLine="true"
android:scrollHorizontally="true"
android:marqueeRepeatLimit="10"
>
</LinearLayout>
Note: when testing the marquee, don't test it in design view inside Eclipse, try it on the emulator\device ..
Also if you want to add a scrolling effect in code:
TextView tView = (TextView) findViewById(R.id.myText);
tView.stSelected(true);
To make the marquee scroll non-stopping on the end of marquee:
android:marqueeRepeatLimit=”marquee_forever”
It's found that the gravity Left/Right are deprecated, a developer should use Start/End. For the text to scroll it needs a "wrap_content" set to its width, additionally the textDirection needs to be set to RTL. For unknown reasons, textDirection did not work programmatically, but worked in the xml.
This code works well on all API versions of android.
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="end"
android:textDirection="rtl"
android:scrollHorizontally="true"
android:scrollbars="horizontal"
android:singleLine="true"
android:ellipsize="none"
android:text="#string/txt_start"
android:textAppearance="?android:attr/textAppearanceLarge" />

TextView with gravity=center and ellipsize=marquee?

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.

Scroll a text automatically on horizontal

I want to scroll a text automatically in horizontal way. I tried the method below, but the text was not scrolling.
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/bg_1"
android:textColor="#cc0000"
android:scrollHorizontally="true"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
/>
So please tell me how to scroll a text and if there is any need to add some code in the class file also.
your TextView don´t scroll because their with must be fill_parent, and the other thing is that the textview must be selected (not pressed) to scroll.
Also, beside what Franco told you, you have set android:ellipsize="marquee"(that truncate the text to fit on that single line you have set), so probably that mix up with the scrolling you set by android:scrollHorizontally="true"
My suggestion is to try to remove the ellipsize property.
i put a listview in above textview so the textview is not scrolling. so itried this one
set listview focusable is false
listview.setfocusable(false);
then it works the text was scrolling.
Try this....
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="John Jonathan Samuwell Abbruzzi"
android:singleLine="true"
android:scrollHorizontally="true"
android:textSize="50sp" />
</HorizontalScrollView>

Categories

Resources