Horizontal scrolling text in Android - 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

Related

How to make running text in cardview android studio?

I want to make layout that look like this :
It similar like Card View and Recycler View
but thing that i want to ask is how to make animation like running text inside the Card View. If the text is to long then the text start moving from right to left like running text.
This is how it looks :
I already searh in google but I can't find the exactly that i want
Your help will be appreciate,
Thanks
You need to add ellipsize property with layout_width of wrap_content or size which you define :
<TextView
android:id="#+id/attatchFilename"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/chooseFile"
android:layout_below="#id/txtMsg"
android:layout_marginTop="10sp"
android:layout_marginLeft="10dp"
android:text=""
android:singleLine="true"
android:focusable="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever" />
You can do this using android:ellipsize="marquee" In you TextView
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="30dp"
android:padding="16dp"
android:id="#+id/sliding_text_marquee"
android:singleLine="true"
android:ellipsize="marquee"
android:text="Scrolling Text (Marquee) in Android Application"
android:textSize="24sp"
android:textStyle="bold" />
First create this animation in xml:
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="5000"
android:fromXDelta="100"
android:interpolator="#android:anim/linear_interpolator"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toXDelta="-100" />
Then add the animation to the TextView:
textview.startAnimation(AnimationUtils.loadAnimation(this, R.anim.scroll_animation));

Android: Need Ellipsis for Multiple TextViews in Relative Layout

I am new to Android, i have below task.
I want to align three TextViews adjacent to each other with ellipsis if the text is too long . Currently i am using below code which aligns my TextView adjacent to each other, but my problem is if the text is too long, the below code not putting the ellipsis. i got some trick to use both toleftof and torightof from here, but in my case it going to circular dependency as mentioned here.
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="#+id/reminderText">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/noteTagOne"
android:ellipsize="end"
android:singleLine="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/noteTagTwo"
android:ellipsize="end"
android:singleLine="true"
android:layout_toRightOf="#+id/noteTagOne"
android:layout_marginLeft="5sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/noteTagThree"
android:layout_toRightOf="#+id/noteTagTwo"
android:ellipsize="end"
android:singleLine="true"
android:layout_marginLeft="5sp"/>
</RelativeLayout>
I want output as,
Tag1... Tag2... Tag3...
Basically, i want some ideas, whether in xml i can achieve this or need to do it programmatically, since TextView text's are dynamic i cannot fix maxLength, sometimes only single tag may exist, at that time it should take full text.
Note: I am developing Android project using C# in Xamarin.
Added code is for the above highlighted part. I fixed overlapping of tagsicon & text. Now only two issues.
1) Last tag is overlapping with right aligned image.
2) If TextView texts are short, gap is shown in-between the tags
How to fix it?
try this solution
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".MainActivity" >
<TextView
android:id="#+id/noteTagOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxWidth="100dp"
android:singleLine="true"
android:text="Tag111111111111111111"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/noteTagTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5sp"
android:layout_toRightOf="#+id/noteTagOne"
android:ellipsize="end"
android:maxWidth="100dp"
android:singleLine="true"
android:text="Tag2222222222222222"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/noteTagThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5sp"
android:layout_toRightOf="#+id/noteTagTwo"
android:ellipsize="end"
android:maxWidth="100dp"
android:singleLine="true"
android:text="Tag3333333333333333"
android:textAppearance="?android:attr/textAppearanceLarge" />
Use this android:ellipsize="marquee" it will work
android:ellipsize="marquee"
or
android:ellipsize="end"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"

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

Moving text in textView 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>

Wrap Text in android?

I want to achieve wrap text in android. I am using following attributes but still couldnt be able to achieve
<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/textview01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="none"
android:scrollHorizontally="false"
android:text="#string/hello" /> // #String/hello <string name="hello">Hello,How are you world whatsup</string>
Anyone please help ?
use this
<TextView
android:id="#+id/textview01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="none"
android:scrollHorizontally="false"
android:text="#string/hello" />
I tried ur code by replacing #string/hello = "Hello,How are you world whatsup. Hello,How are you world whatsup" and it worked fine.
may be other views in ur layout are affecting your TextView
try adding "android:layout_weight="1""

Categories

Resources