How do I get text to Marquee in the Android-wheel?
I am using the android-wheel http://code.google.开发者_C百科com/p/android-wheel/ in an application.
I have three of the wheels side by side on my screen. When the text in a wheel is wider than the wheel I would like it to scroll to the side (As per Marquee)
I have implemented an AbstractWheelTextAdapter
and created a custom ScrollingTextView
for the items as follows: (ScrollingTextView
is to overcome the issue with Marquee only working when an item has focus)
public class ScrollingTextView extends TextView {
public ScrollingTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public ScrollingTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ScrollingTextView(Context context) {
super(context);
}
@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;
}
}
And the xml:
<com.test.app.ScrollingTextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id = "@+id/wheel_text"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:inputType="text"
android:scrollHorizontally="true"
android:textColor="#F000"
android:lines="1"
android:focusable="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusableInTouchMode="true"/>
Has anyone been able to get this to work?
(I have also tried setting the Ellipse in the code for the AbstractWheelTextAdapter
without success)
Because the WheelView didn't invalidate itself.In Activity,add the code :
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
wheelview.invalidate();
sendEmptyMessageDelayed(0, 0);
}
};
handler.sendEmptyMessage(0);
Then the TextView Marquee effect works.But when you scroll the WheelView,the TextView string reset from start.
I had try the TextView Marquee effect in ListView, the Marquee effect works.I gonna check the ListView source code ,see what differences between ListView and WheelView.
精彩评论