为什么Widget 桌面小窗口 不能使用TabLayout呢?解决办法

为什么Widget 桌面小窗口 不能使用TabLayout呢?1.一模一样的2个TableLayout布局的.xml文件,一个用来做Main

为什么Widget 桌面小窗口 不能使用TabLayout呢?
1.一模一样的2个TableLayout布局的.xml文件,一个用来做MainActivity的layout可以正常显示,没有任何问题,证明.xml文件本身是没有写错的

2.appwidget-provider中的android:initialLayout="@layout/main"指向main 同时,在MyAppWidgetProvider中,remoteViews = new RemoteViews(context.getPackageName(),R.layout.main);同样指向main 。当我main使用LinearLayout没有错,可以正常运行,但是使用TableLayout就立马出错。刚才上面已经说过了,这个TableLayout是没有问题的。


问: 是不是 widget桌面小窗口不能使用TableLayout呢?若是可以用,该如何正确的使用啊?????


以下是代码:

1.appwidget-provider代码,定义Widget属性

XML code
<?xml version="1.0" encoding="utf-8"?><appwidget-provider  xmlns:android="http://schemas.android.com/apk/res/android"  android:minWidth="260dip"  android:minHeight="50dip"  android:updatePeriodMillis="1000"  android:initialLayout="@layout/main"/>


2.TableLayout 文件 想在widget中写一个表格布局所建
XML code
<?xml version="1.0" encoding="utf-8"?><TableLayout  xmlns:android="http://schemas.android.com/apk/res/android"  android:orientation="vertical"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:background="@drawable/sucai1">      <TextView        android:text="Table Test"        android:gravity="center"/>    <TableRow>        <TextView            android:layout_column="1"            android:text="姓名"            android:gravity="center"/>        <TextView            android:text="基本信息"            android:gravity="center"/>    </TableRow>    <TableRow>        <TextView            android:text=" 1 "            android:gravity="center"/>        <TextView            android:text="hoyah"            android:gravity="left"/>        <TextView            android:text="Wuhan University"            android:gravity="right"/>    </TableRow>    <TableRow>        <TextView            android:text=" 2 "            android:gravity="center"/>        <TextView            android:text="Google"            android:gravity="left"/>        <TextView            android:text="hello Google"            android:gravity="right"/>    </TableRow>    <TableRow>        <TextView            android:text="3"            android:gravity="center"/>        <TextView            android:text="Android"            android:gravity="left"/>        <TextView            android:text="Android OS"            android:gravity="right"/>    </TableRow></TableLayout>


3.AppWidgetProvider类 控制Widget的更新与显示
Java code
public class WidgetDemoActivity extends AppWidgetProvider {        public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {                Timer timer = new Timer();        timer.scheduleAtFixedRate(new MyTime(context,appWidgetManager), 1, 60000);        super.onUpdate(context, appWidgetManager, appWidgetIds);    }        private class MyTime extends TimerTask{        RemoteViews remoteViews;        AppWidgetManager appWidgetManager;        ComponentName thisWidget;        public MyTime(Context context, AppWidgetManager appWidgetManager) {            this.appWidgetManager = appWidgetManager;            remoteViews = new RemoteViews(context.getPackageName(),R.layout.main);            thisWidget = new ComponentName(context,WidgetDemoActivity.class);        }        @Override        public void run() {            Date date = new Date();            Calendar calendar = new GregorianCalendar(2012, 00, 23);            long days = (((calendar.getTimeInMillis()-date.getTime())/1000))/86400;            remoteViews.setTextViewText(R.id.sucai1, "距离2012年春节还有" + days + "天");            appWidgetManager.updateAppWidget(thisWidget, remoteViews);        }    }} 



[解决办法]
你可以查看android的文档,不是所有的控件都可以使用在widget上边的,只有部分可以例如TextView等,TableLayout不在支持的之列
[解决办法]
http://developer.android.com/guide/topics/appwidgets/index.html
你会发现android默认的widget并不支持TabLayout,所以你需要替换TabLayout,或者修改framework反编译源码