1

当我在家中添加小部件时,我有几个过程,我如何在它还没有准备好时添加“加载图像”?

我看到 Youtube 小部件有这个。

谢谢!

4

2 回答 2

4

我做到了!=)

我不知道这是否是最好的方法,让我告诉你:

在我的小部件 xml 上,我添加了第二个布局,它包含进度条:

widget_layout.xml

<LinearLayout android:id="@+id/progressLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ProgressBar android:id="@+id/widgetProgressBar" android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

我在原始布局中添加了以下代码:

android:visibility="gone"

然后,当我的所有过程结束时,我这样做了:

RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);

remoteViews.setViewVisibility(R.id.progressLayout, View.GONE);
remoteViews.setViewVisibility(R.id.layout, View.VISIBLE);

appWidgetManager.updateAppWidget(widgetId, remoteViews);

如果有人有更好的方法,请告诉我们!

于 2012-12-20T14:26:29.667 回答
0

您是否尝试过进度条?当您开始该过程时,您可以使用以下代码:

ProgressDialog mDialog;  //create a member vairable


//put this in what ever method you start your process
mDialog = new ProgressDialog(getApplicationContext());
mDialog.setMessage("Loading...");
mDialog.setCancelable(false);
mDialog.show();

完成所有流程后,您可以致电:

//call this when all processes are finished
mDialog.cancel();
于 2012-12-19T21:31:13.840 回答