如何在小部件中添加加载

Otu*_*uyh 2 android android-widget

当我在家里添加小部件时,我有几个过程,如何在尚未准备好时添加“加载图像”?

我看到 Youtube 小部件有这个。

谢谢!

Otu*_*uyh 6

我做到了!=)

我不知道这是否是最好的方法,让我向您展示:

在我的小部件 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>
Run Code Online (Sandbox Code Playgroud)

我在原来的布局上添加了以下代码:

android:visibility="gone"
Run Code Online (Sandbox Code Playgroud)

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

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);
Run Code Online (Sandbox Code Playgroud)

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