存储小部件位置

时间:2014-01-23 12:57:02

标签: android-widget

如何在创建小部件或onEnabled时存储/获取小部件x,y坐标? 我想得到它们,因为我想在我的小部件ImageView中添加2个imageViews网 这是我的代码

public class MyWidgetProvider extends AppWidgetProvider {
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    final int N = appWidgetIds.length;

    for (int i=0; i<N; i++) {
        int appWidgetId = appWidgetIds[i];

        Intent intent = new Intent(context, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
        views.setOnClickPendingIntent(R.id.imageView1, pendingIntent);

        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}

@Override
public void onEnabled(Context context) {
    // TODO Auto-generated method stub
    super.onEnabled(context);
    Toast.makeText(context, "Welcome to QNotes Application :)", Toast.LENGTH_LONG).show();
}

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    super.onReceive(context, intent);
    Toast.makeText(context,"asd", Toast.LENGTH_LONG).show();

}

1 个答案:

答案 0 :(得分:0)

我改变了主意,改为使用透明活动。