Moving text in textView android - android

I would like to ask you if textview has any option that when I have too long text for example text has 30 dp and textview has 15 dp I want to show text which is moving from left corner to right and return to start and again. Something like animation. I want to user see all text. Something like automatic scroll.
Edit: How I can do that in code, not xml?

an example -
in the XML :
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:textColor="#ff4500"
android:text="this is a very long piece of text that will move" />
</RelativeLayout>
in Java:
tv = (TextView) this.findViewById(R.id.tv);
tv.setSelected(true); // Set focus to the textview

You should use android:ellipsize="marquee".
EDIT: you can use textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);

<TextView
android:id="#+id/YOURID"
android:layout_width="15dp"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
/>
This will help it to scroll until it is focused

Use this code, it's working 100%:
TextView top=new TextView(this);
top.setText("Developers are working to add more features");
top.setEllipsize(TextUtils.TruncateAt.MARQUEE);
top.setHorizontallyScrolling(true);
top.setMarqueeRepeatLimit(-1);
top.setFocusable(true);
top.setFocusableInTouchMode(true);

Yes, its called marquee. Set the following to your TextView:
android:singleLine="true"
android:ellipsize="marquee"

Try this 3 lines codes: (a summary of the above)
textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
textView.setSingleLine(true);
textView.setSelected(true);

In order to move text, besides adding attributes:
android:ellipsize="marquee"
android:singleLine="true"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:clickable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
it is necessary for View to be in focus, so this can be done in two ways:
Programmatically:
tv.setSelected (true);
Do everything in XML by adding requestFocus tag:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:singleLine="true"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:clickable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true">
<requestFocus />
</TextView>

Related

Auto show rest of TextView

How to make single line TextView appears if the screen small?, Because it's makes 3 dots of ellipsize without defining it in XML and the rest of text disappeared.
Example:
Please add:
android:singleLine="false"
OR
android:inputType="textMultiLine"
to your TextView
EDIT:
Your TextView can look something like this:
<TextView
android:id="#+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/your_text"
android:maxLines = "1"
android:scrollbars = "vertical"/>
and add these two lines to your onCreate
TextView yourTextView = (TextView) findViewById(R.id.test);
yourTextView.setMovementMethod(new ScrollingMovementMethod());
Not too clean but does the job.
SECOND EDIT:
<TextView
android:text="#string/yourText"
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever" <!-- Please change according to requirement -->
android:scrollHorizontally="true"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:focusable="true"
android:focusableInTouchMode="true"
android:freezesText="true"/>
Hope this helps!

How to make Google Play like TextView animation when text is too long?

In Google Play when the name of a certain title is too long then they apply an animation on this TextView when the name is going out from one end of the TextView, goes in from the other end, stops for a second on the beginning of the Title text, and then goes for the next round.
Does anyone have any explanation how can this be achieved?
This was what worked for me, you have to actually request for focus in order for the marquee animation to work:
<TextView
android:id="#+id/tvAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvName"
android:layout_toLeftOf="#+id/ivLogo"
android:text=""
android:textColor="#color/cups_white"
android:textSize="18sp"
android:ellipsize="marquee"
android:singleLine="true"
android:marqueeRepeatLimit ="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:duplicateParentState="true">
<requestFocus
android:focusable="true"
android:focusableInTouchMode="true"
android:duplicateParentState="true" />
</TextView>
In your xml file where the TextView is declared you can use the following attributes:
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
with the singleline you going sure thats the Text is showend only in one line.
For more details look at this: http://developer.android.com/reference/android/widget/TextView.html

Android: TextView is not scrolling Automatically

I have a TextView with following attributes :
<TextView
android:id="#+id/appheader"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:textColor="#ffffff"
android:layout_marginLeft="3dp"
android:textSize="21sp"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"/>
Actually the TextView scrolls ONLY when I click the TextView. But I want to scroll it automatically when I launch the Activity. How can I do this ?
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="very long text to srollll dkfjadkfjkldjfkjdkghjhtudhfjhdjfkdfkadjsajekdfjak"
android:singleLine="true"
android:marqueeRepeatLimit="marquee_forever"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"/>
By-default TextView marquee effect works when it get focus. To make an automatic marquee effect you need to extend TextView class. See this link for reference.
set android:scrollHorizontally="true" for that textview.
Also set the following two properties:
text.setMovementMethod(new ScrollingMovementMethod());
text.setSelected(true);

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>

Horizontal scrolling text in Android

I've been looking around for quite some time now, and I can't get a straight answer for my question.
It's quite simple: How can I get a nice scrolling text just like the long app names in the Market when you select an application?
I've figured it out by myself.
android:ellipsize="marquee"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
Make a translate animation in your anim folder like:
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="12000"
android:fromXDelta="100"
android:interpolator="#android:anim/linear_interpolator"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toXDelta="-100" />
And then to your textview like:
yourtextview.startAnimation((Animation)AnimationUtils.loadAnimation(Context,R.anim.youranim_xml));
Hope this might help you.
Edit:
Try this:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:lines="1"
android:marqueeRepeatLimit="marquee_forever"
android:padding="4dp"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Simple application that shows how to use marquee, with a long text" />
the decision which works for me:
textView.setSelected(true);
textView.setEllipsize(TruncateAt.MARQUEE);
textView.setSingleLine(true);
without focusable's parameters
android:ellipsize="marquee"
Use a normal TextView with the following config:
android:text="your text here"
android:id="#+id/MarqueeText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true" />
The problem with this is that you cannot adjust the speed of the scrolling text.
Enclose a TextView within a ScrollView:
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/myTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Your Text here" >
</TextView>
</ScrollView>
Create custom class and follow this thread

Categories

Resources