2

我在应用程序中使用 android-wheel http://code.google.com/p/android-wheel/ 。

我的屏幕上有三个并排的轮子。当轮子中的文本比轮子宽时,我希望它滚动到一边(根据选框)

我已经为这些项目实现AbstractWheelTextAdapter并创建了一个自定义ScrollingTextView,如下所示:(ScrollingTextView是为了克服 Marquee 仅在项目具有焦点时工作的问题)

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;

}

}

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

有没有人能让这个工作?

(我也尝试在代码中设置椭圆AbstractWheelTextAdapter但没有成功)

4

1 回答 1

0

因为 WheelView 本身并没有失效。在 Activity 中,添加代码:

Handler handler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        super.handleMessage(msg);
        wheelview.invalidate();
        sendEmptyMessageDelayed(0, 0);
        }
};  
handler.sendEmptyMessage(0);

然后 TextView Marquee 效果起作用。但是当您滚动 WheelView 时,TextView 字符串从开始重置。

我在 ListView 中尝试了 TextView Marquee 效果,Marquee 效果有效。我去查看 ListView 源代码,看看 ListView 和 WheelView 有什么区别。

于 2014-05-19T10:13:59.347 回答