如何将文本发送到 Android 轮盘中的选框?

发布于 2024-12-02 08:17:16 字数 1740 浏览 0 评论 0原文

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

我的屏幕上并排有三个轮子。当轮子中的文本比轮子宽时,我希望它滚动到侧面(按照选框)

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

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 的代码中设置 Ellipse ,但没有成功)

I am using the android-wheel http://code.google.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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青丝拂面 2024-12-09 08:17:16

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

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

然后TextView跑马灯效果就起作用了。但是当你滚动WheelView时,TextView字符串从头开始重置。

我在ListView中尝试过TextView跑马灯效果,跑马灯效果有效。我要检查ListView源代码,看看ListView和WheelView之间有什么区别。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文