单击更改可见性以隐藏一个 ImageView 并延迟显示其他 ImageView 以生成动画 android 小部件

Changing Visibility on click to hide one ImageView and appear other ImageView with delay to generate animation android widget

我需要 Android 应用程序的小部件方面的帮助,

我想用两个 ImageView 为刷新按钮设置动画。单击时,第一个图像应该隐藏,并且应该出现旋转 180° 的刷新按钮图像。稍稍延迟后,180° 旋转的 ImageView 应该再次隐藏,第一个 ImageView 应该出现。

最后我想更新Widget。

我很高兴有更好的想法来为 Android 小部件中的刷新按钮设置动画。所有 Whosebug 结果都在谈论正常的应用程序...

在使用服务器调用时,我们现在可以在 AsynCall 方面取得进展 像这样修复它

Img1.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {

        //Hide the First Image
        //Show the 2nd Img after 3 Sec 

          DelayMethod();

    }
});

public void DelayMethod(){
 new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {

            //Show the 1st Img after 3 Sec

        }
    },3000);
}

也许将两个图像(可能添加更多具有不同角度的图像以使动画更流畅)放在视图翻转器中,然后将其设置为 android:autoStart="true" android:inAnimation="@android:anim/fade_in" android:outAnimation="@android:anim/fade_out" android:animateFirstView="true"然后使用android:flipInterval="10000"根据需要设置翻转间隔。 一旦小部件准备就绪,您就可以停止翻转。

翻转视图参考:

这是我自己的问题的解决方案:

我创建了一个 PendingIntent 来监听按钮。

remoteviews.setOnClickPendingIntent(R.id.refresh_btn,
            getPendingSelfIntent(context, BTN_REFRESH));

protected PendingIntent getPendingSelfIntent(Context context, String action) {
    Intent intent = new Intent(context, getClass());
    intent.setAction(action);
    return PendingIntent.getBroadcast(context, 0, intent, 0);
}

我使用全局 toggleState 并调用一个方法:

private void refresh(RemoteViews remoteviews, Context context) {
    if (toggleState) {//if Button gets clicked onReceive will update all widgets
        remoteviews.setViewVisibility(R.id.refresh_btn, View.GONE);
        remoteviews.setViewVisibility(R.id.refresh_btn_rev, View.VISIBLE);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                toggleState = false;
                updateAllWidgets(context);
            }
        }, 500);
    } else {
        remoteviews.setViewVisibility(R.id.refresh_btn, View.VISIBLE);
        remoteviews.setViewVisibility(R.id.refresh_btn_rev, View.GONE);
    }
}

如果单击 Button,则 toggleState 设置为 true。