在Android中向RemoteView添加视图

在Android中向RemoteView添加视图,android,widget,Android,Widget,直截了当地说 //This is my main layout RemoteViews views = null; views = new RemoteViews(getPackageName(), R.layout.main); //Clear parent view views.removeAllViews(R.id.llMain); //This is how we add nested view RemoteViews childView = new RemoteViews(get

直截了当地说

//This is my main layout
RemoteViews views = null;
views = new RemoteViews(getPackageName(), R.layout.main); 

//Clear parent view
views.removeAllViews(R.id.llMain);

//This is how we add nested view
RemoteViews childView = new RemoteViews(getPackageName(), R.layout.lay_child);
views.addView(R.id.llMain, childView);
这些代码在Galaxy Nexus上运行良好。但在Galaxy Tab或Motorola等其他设备上则不然。怎么了

它返回类似“找不到视图。改用错误视图”的错误消息 updateAppWidget无法使用错误视图找到任何视图 android.widget.RemoteViews$ActionException:找不到视图:0x7f050025

//This is the main layout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#00000000"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <LinearLayout
        android:id="@+id/llMain"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"    
        android:orientation="vertical"
        android:layout_gravity="center|left"
        android:layout_marginLeft="@dimen/marginLeft">  

    </LinearLayout>             

</FrameLayout>
//这是主布局
这是child视图

lay_child.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/llTimezoned"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:visibility="visible"
    android:layout_gravity="center">                    
    <ImageView android:id="@+id/ivTimezone"
        android:layout_width="60dp"
        android:layout_height="60dp"
        />     
</LinearLayout>

还是与操作系统版本有关

这对我有用

RemoteViews update = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
    for (int i = 0; i < 3; i++) {
        RemoteViews textView = new RemoteViews(context.getPackageName(), R.layout.test);
        textView.setTextViewText(R.id.textView1, "TextView number " + String.valueOf(i));
        update.addView(R.id.ll_widget, textView);
    }

    appWidgetManager.updateAppWidget(appWidgetIds, update);
RemoteViews update=新的远程视图(context.getPackageName(),R.layout.widget\u布局);
对于(int i=0;i<3;i++){
RemoteViews textView=新的RemoteView(context.getPackageName(),R.layout.test);
textView.setTextViewText(R.id.textView1,“textView编号”+String.valueOf(i));
update.addView(R.id.ll_小部件,textView);
}
UpdateAppWidgetManager.UpdateAppWidgetId(AppWidgetId,update);