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>
Related
I am making a UI which will look like this
My goal is to add marquee scroll effect in highlighted text views, The parent container for the both text view is Constraint layout, Hence I am using android:layout_width="0dp" so that my view expands to its constraints that is 50-50 of the total space.
I did some research and found that I need android:layout_width="match_parent" in order to achieve marque.
My current code for marquee:
<TextView
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:singleLine="true"
android:focusableInTouchMode="true"
android:freezesText="true"
android:scrollHorizontally="true"
android:gravity="start"
android:id="#+id/row_load_list_toAddress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="End Location"
android:textColor="#color/black"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/imageView5"
app:layout_constraintTop_toBottomOf="#+id/textView13" />
Anyone please put a light on what I might be doing wrong here and what is the solution?
Inorder for the marquee to work you must set setSelected property to true in your Activity related to that layout
TextView txt = findViewById(R.id.row_load_list_toAddress);
txt.setSelected(true);
Hope this will fix your problem.
I have a TextView that takes in Strings and I want the TextView to scroll to the last text added on the right automatically. The ScrollView works but I have to scroll manually to the last text added when it's out of the TextView's field of view. Please help.
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.5"
android:fillViewport="true"
android:scrollbars="none">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:scrollHorizontally="true"
android:textColor="#android:color/black"
android:textSize="24sp" />
</HorizontalScrollView>
yourScrollView.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
I solved this problem through the use EditTextView instead of TextView and disabling focusEnabled by setting keyListener to null in order to achieve the behavior of a normal TextView and also scroll automatically like I wanted.
I understand that this might be a duplicate, but I havent found an answer.....yet!
How can I make a smooth horizontal scrolling text in my Android-app? I want the text to scroll like a stockticker on the TV-news. I also need a callback when the scrolling is completed so i can set a new text to scroll.
What is the best way to do this?
Thanks!
Good Question.
First of all to do this, place following code in your layout file for TextView
android:ellipsize="marquee"
android:focusable="false"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
Then write following code in your code file,
TextView txt = (TextView) findViewById(R.id.textView);
txt.setSelected(true);
You must give setSelected(true) to make textview scroll automatically.
Thanks.
For Manually Scrolling
<HorizontalScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="40dp"
android:layout_height="wrap_content"
android:scrollHorizontally="true"
android:text="Horizontal scroll view is working"/>
</HorizontalScrollView>
For Automatic Scrolling
<TextView
android:text="Single-line text view that scrolls automatically if the text is too long to fit "
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
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>
hai,
i have custom listview in that page should have the horizontal scrolling text. But the horizontal text is not scrolling. so please help me anyone.
i used following xml code.
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_x="2px"
android:layout_y="690px"
android:background="#drawable/bg_1"
android:textColor="#cc0000"
android:scrollHorizontally="true"
android:singleLine="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:ellipsize="marquee"
/>
Thank you in advance.
Isn't "ellipsize" a typo? Don't you mean "ellipsis"?
set listview focusable is false
listview.setfocusable(false);