私はWiFiに簡単にアクセスできるWiFiウィジェットを作成しました。 ウィジェットの機能がうまく機能しています。 今、ウィジェットにアニメーションを表示したいと思います。信号バーを接続している間は、Wi-Fiが有効になるまで定期的に点灯して上に移動します。 私は、異なる信号レベルのイメージアレイを作成しました。AndroidでAppWidgetアニメーション
私はメソッドstartAnimationを呼び出していますが。
public void StartAnimation()
{
System.out.println("start");
frame = 0;
animationFlag = true;
if(!handler.hasMessages(0))
handler.postDelayed(AnimateRunnable, FRAME_RATE);
}
satrtAnimationから、私はanimationFlagをtrueにしています。
その後、状態はEnbaledまたはNot connectedになります。そのとき、私はstopAnimationメソッドを呼び出しています。
public void StopAnimation()
{
System.out.println("Stop Animation Before:"+animationFlag);
animationFlag = false;
System.out.println("Stop Animation:After:"+animationFlag);
if(!handler.hasMessages(0)) {
System.out.println("handler.hasmessage0");
handler.removeCallbacks(AnimateRunnable);
}
}
ここでは、animationFlagをfalseにしています。前後の値を印字する。正しく表示されます。
しかし、「My Runnable」アニメーションフラグはtrueのままです。だから私のウィジェットアプリウィジェットのレイアウトは、アプリケーションで定義されているという事実にもかかわらず
final Runnable AnimateRunnable =new Runnable(){
public void run()
{
System.out.println("run:"+animationFlag);
if(animationFlag)
{
System.out.println("Animation Flag:"+animationFlag);
AppWidgetManager ap =AppWidgetManager.getInstance(mContext);
frame = ++frame%5;
remoteViews.setImageViewResource(R.id.wifi_signal_strength,rangeImages[frame]);
ap.updateAppWidget(thisWidget, remoteViews);
handler.postDelayed(AnimateRunnable, FRAME_RATE);
}
}
};