android - TextView 选取框

标签 android android-widget

我想在主屏幕上放一个textView,我需要跑马灯效果

public class MainWidget extends AppWidgetProvider {
int a;
RemoteViews remoteViews;
AppWidgetManager appWidgetManager;
ComponentName thisWidget;

String[] s={"woddfdfdfdfdfdffffffffffffffffffffffffffffffff","dd","ddd","ffff"};
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
      int[] appWidgetIds) {
      Timer timer = new Timer();
      timer.scheduleAtFixedRate(new WlanTimer(context, appWidgetManager), 100, 50000);
}

private class WlanTimer extends TimerTask {
        RemoteViews remoteViews;
        AppWidgetManager appWidgetManager;
        ComponentName thisWidget;

public WlanTimer(Context context, AppWidgetManager appWidgetManager) {

        this.appWidgetManager = appWidgetManager;
        remoteViews = new RemoteViews(context.getPackageName(), R.layout.marketwidget_main);
        thisWidget = new ComponentName(context, MainWidget.class);
}

@Override
public void run() {
a=(int) (Math.random()*3);                            
        remoteViews.setTextViewText(R.id.TextView_marketwidget_main_marketmessage,s[a]);
    appWidgetManager.updateAppWidget(thisWidget, remoteViews);
    }
}
}

如果我使用 s[0] 而不是 s[a],它不会运行,只会显示“woddfdf”。

我的 textView xml 是:

 <TextView android:id="@+id/TextView_marketwidget_main_marketmessage"
    android:maxLines="1" android:focusable="true"
    android:ellipsize="marquee"
    android:inputType="text"
    android:focusableInTouchMode="true" android:marqueeRepeatLimit="marquee_forever" android:textColor="#ffffff" android:background="@android:color/transparent" android:layout_width="80dip" android:layout_height="20dip"></TextView>

最佳答案

我从你的问题中得到的是,你想在 TextView 中显示滚动字幕效果? 如果我是对的,请执行以下操作。

在布局文件 (XML) 的 TextView 元素中设置 android:ellipsize="marquee"。然后,在 Activity 的 onCreate() 方法中,添加行 textView.setSelected(true);.

注意:将名称 textView 替换为您的 TextView 的名称。

返回任何查询。

关于android - TextView 选取框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4332819/

相关文章:

android - 如何在 Android 上使用寻址和验证 PostCodeAnywhere?

Android:EditText 重新启用后无法获得焦点

android - 小部件 ImageButton 监听器并不总是被调用

android - Robolectric 单元测试 build.os 版本返回不正确?

java.net.ConnectException : Connection refused TCP

android - float 操作按钮变形

android - 如何在Android 4.0 默认日历中添加事件?

android - 实现具有动态绘制内容的 Android 小部件的正确方法是什么?

android - AppWidgetHost 不更新小部件

android - 在模拟器上测试 Android 应用程序的一套好的设备配置是什么?