Android's spinner automatic scrolling when text is too long - android

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.

Related

TextView marquee WITHOUT android:layout_width="match_parent"

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.

How to marquee ListView in android?

I want to marquee my listview in android up to end of my listview item and at the end repeat marquee my listview. Tell me how I can do that.
you want to marquee listview or listview's items like textview ?for textview you can use this
<TextView
android:id="#+id/fact"
android:layout_width="200dp"
android:layout_height="40dip"
android:duplicateParentState="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Loading... More text to see if it spans or not and want more">
<requestFocus
android:duplicateParentState="true"
android:focusable="true"
android:focusableInTouchMode="true" />
</TextView>

Smooth horizontal scrolling text

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

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>

can listview supports horizontal scrolling text

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);

Categories

Resources