0

直奔问题。

//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 或摩托罗拉。怎么了?

它返回错误消息,例如“找不到视图。改用错误视图”。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>

这是子视图

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>

还是与操作系统版本有关?

4

1 回答 1

1

这对我有用

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);

https://stackoverflow.com/a/20040066/1492815

于 2013-12-29T01:54:38.543 回答