各位:
我要在widget上实现一个文字滚动的功能,在widget上有个TextView,在TextView(见下面的布局文件)上实现文字滚动,在Activity内的TextView可以实现文字滚动功能,但是不知道为什么在widget上却不行,哪位高手告知一下,不胜感激。
我的布局文件如下:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="280dp"
android:layout_height="123dp">
<ImageView android:id="@+id/imageview" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:src="@drawable/frame" />
<TextView android:id="@+id/textview" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#F00"
android:textSize="25sp"
android:gravity="center"
android:scrollHorizontally="true"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:marqueeRepeatLimit="marquee_forever"
android:focusableInTouchMode="true"
android:duplicateParentState="true"
/>
</FrameLayout>
我要在widget上实现一个文字滚动的功能,在widget上有个TextView,在TextView(见下面的布局文件)上实现文字滚动,在Activity内的TextView可以实现文字滚动功能,但是不知道为什么在widget上却不行,哪位高手告知一下,不胜感激。
我的布局文件如下:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="280dp"
android:layout_height="123dp">
<ImageView android:id="@+id/imageview" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:src="@drawable/frame" />
<TextView android:id="@+id/textview" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#F00"
android:textSize="25sp"
android:gravity="center"
android:scrollHorizontally="true"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:marqueeRepeatLimit="marquee_forever"
android:focusableInTouchMode="true"
android:duplicateParentState="true"
/>
</FrameLayout>
解决方案 »
- 虚拟鸡是在谷歌发布系统的时候集成进去的?
- android:如何用Ksoap2来把数组或列表作为参数传给一个webservice
- android listView显示实体数据
- android2.3模拟器如何上优酷看视频
- 求Tom猫中的监听声音的方法
- android xml的问题,求指点
- 菜鸟才进入android,好多都不懂求指导。
- android 4.0以上版本系统时间选择器样式问题
- android progressbar的白色背景怎么去掉
- android 实现所有的界面都公用一个菜单
- 手机QQ以及微信聊天的界面 ,listview是怎么实现的?就是别人说话是左边,自己说话是右边,谁研究过这个界面啊?多给说说~
- android inputdispatcher deadlock问题
public class MyWidget extends AppWidgetProvider {
RemoteViews rv;
MyHandler handler;
AppWidgetManager manager;
int[] ids;
String str = "今天是星期五,明天我们放假!";
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
ids = appWidgetIds;
manager = appWidgetManager;
handler = new MyHandler();
handler.sendEmptyMessageDelayed(0, 1000);
rv = new RemoteViews(context.getPackageName(), R.layout.main);
rv.setTextViewText(R.id.text, str);
appWidgetManager.updateAppWidget(appWidgetIds, rv);
// TODO Auto-generated method stub
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
private String go(String str){
return str.substring(1) + str.substring(0, 1);
}
class MyHandler extends Handler{ @Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
str = go(str);
rv.setTextViewText(R.id.text, str);
rv.setTextViewText(R.id.time, getFormatTime(new Date()));
manager.updateAppWidget(ids[0], rv);
handler.removeMessages(0);
handler.sendEmptyMessageDelayed(0, 300);
}
}
}
跑马灯效果:http://blog.csdn.net/ch_984326013/article/details/6627280
确定不能用TextView实现效果么 专门起个service刷新widget ,太耗资源了
因为AppWidget是从Receiver继承来的,而不是Activity,所以其表现能力很差,只能通过RemoteView,所以RemoteView有的就能实现,没有的就不能实现。当然也可以像4楼那样变通的实现。看看SDK就知道AppWidget在Android3.0之后才支持ListView等