Reputation: 31
I'm currently playing with the marquee feature of Android's Textview. But there is a problem- I have a layout containing a few TextView. On one of them, which shows a title of an music file, I want to apply the marquee feature. On another, I keep updating the current track time (every second).
The problem is, everytime the TextView which shows the track time is updated (setText()), the marquee of the other TextView stops. I guess this is because setTExt() moves the focus to the TextView which I to apply the text to.
Is there a solution for this?
I used a custom class for the marquee TextView from this tutorial
Is there a possibility (maybe a custom class as well) for the other TextView to not "steal" focus?
Thanks!
Regards
Upvotes: 3
Views: 4490
Reputation: 1596
You can simply wrap the marquee TextView with a LinearLayout
Upvotes: 0
Reputation: 219
See my answer here : https://stackoverflow.com/a/13841982/1823503
The idea is :
Upvotes: 1
Reputation: 11074
In my case setEnabled(true)
hasn't hepled. Neither requesting focus, nor anything of the sort, because it hasn't been a problem with focus. I believe marquee also restarts whenever the TextView goes through onLayout()
.
In my case the TextView was inside a LinearLayout that had layout_height="wrap_content"
. The TextView showing the track time was below the TextView with marquee. Now when each second I was updating the lower TextView, then I believe the OS computed it's height from scratch and also computed the height of the whole LinearLayout based on the height of TextView (which, of course, was the same every time). A that's why the whole LinearLayout (and it's children) was getting onLayout()
which restarted the marquee.
Long story short, I set the height of my container LinearLayout to a fixed value and marquee started to work.
Upvotes: 4
Reputation: 417
But there is a problem- I have a layout containing a few TextView. I found the solution here: http://androidbears.stellarpc.net/?p=185
You should extend TextView class and override several methods
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
if(focused)
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
@Override
public void onWindowFocusChanged(boolean focused) {
if(focused)
super.onWindowFocusChanged(focused);
}
@Override
public boolean isFocused() {
return true;
}
Upvotes: 3
Reputation: 98501
Marquee is enabled when a TextView is setEnabled(true) or receives focus. Use setEnabled(true) to make sure other TextViews won't stop their marquee when focus moves.
Upvotes: 4
Reputation: 76556
You can simply requestFocus(); back onto the TextView you want to marquee after the new music TextView has updated. If you can't accomplish this, post some code an we can help.
Upvotes: 1