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"/>
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.
In my layout there is a spinner (drop-down list) with fixed width, some entries are longer than the spinner so I want them to automatically scroll horizontally when chosen.
I know you can apply automatic horizontal scroll to textview like this:
<TextView
android:id="#+id/textView1"
android:layout_width="50dp"
android:layout_height="25dp"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Single-line text view that scrolls automatically if the text is too long to fit in the widget" />
I tried to apply same settings to my spinner as follows:
<Spinner
android:id="#+id/spinner1"
android:layout_width="90dp"
android:layout_height="55"
android:ellipsize="marquee"
android:entries="#array/country_arrays"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true" />
But it doesn't scroll. Any ideas?
A Spinner extends AdapterView which is backed by an Adapter class.
So much like you can customise each row in a ListView, you should be able to do the same for your Spinner by overriding a method like Adapter.getView().
There you could return a simple TextView with the ellipsize property.
Hope it helps you a lot.
I am very new to Android programming, and I have read everywhere and I can't seem to find any solution.
Basic problem is that I have a TextView in a widget and I would like the text to scroll when the text is longer than the TextView layout_width. This is my code in the layout_widget.xml
<TextView android:id="#+id/fact" android:layout_width="200dp"
android:text="Loading... More text to see if it spans or not and want more"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true" />
Now I read that I have to make the TextView to be on focus, which I have done. I have also read that you need to set the property setSelected(true), and this is where I am struggling to set. In my default Activity (in the AndroidManifest.xml) I have this following code.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.widget_layout);
findViewById(R.id.fact).setSelected(true);
setContentView(R.layout.main);
}
The part below is used to set the Content to the widget_layout.xml and then set the TextView property for setSelected to true
setContentView(R.layout.widget_layout);
findViewById(R.id.fact).setSelected(true);
I then return the ContentView back to main.xml
Now I am guessing this is wrong and this is not the way it should be done. But I am wondering if it can be done. I also read that if you can override the Framework, you can put your own properties in, for example ScrollView, is this right as well? Also I am on SDK Version 7.
I much appreciate the help I receive, thanks all!
Edit: By removing setContentView(R.layout.main); when launching the application via the app draw, the text does scroll, but the widget doesn't. Kind of leads me to that a widget cannot have a marquee??? Has anyone got a marquee working on a widget??
Edit2: Solved. This is how it is done
In the xml for the text view you need to have a tag This basically I think is the same as getSeleted(true);
So the code should be as followed:
<TextView android:id="#+id/fact" android:layout_width="200dp"
android:text="Loading... More text to see if it spans or not and want more"
android:singleLine="true"
android:ellipsize="marquee"
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>
Solved. This is how it is done
In the xml for the text view you need to have a tag This basically I think is the same as getSeleted(true);
So the code should be as followed:
<TextView android:id="#+id/fact" android:layout_width="200dp"
android:text="Loading... More text to see if it spans or not and want more"
android:singleLine="true"
android:ellipsize="marquee"
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>
You are calling setContentView twice:
setContentView(R.layout.widget_layout);
findViewById(R.id.fact).setSelected(true);
setContentView(R.layout.main);
Your activity can only have one layout. If widget_layout is the layout for your widget that includes the text view, then you don't want the second setContentView.
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>
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);