Android 旋转刷新按钮
我在布局文件中定义了一个刷新按钮,如下所示:Android 旋转刷新按钮,android,Android,我在布局文件中定义了一个刷新按钮,如下所示: <ImageButton android:id="@+id/btn_refresh_assets" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:onClick="onClick" android:
<ImageButton
android:id="@+id/btn_refresh_assets"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:onClick="onClick"
android:src="@drawable/ic_menu_refresh" />
当他的按钮被点击时,会调用一个AsyncTask
,从Web服务加载数据。现在我想旋转刷新图标,直到加载完成!!!
在ActualBar中有一些指导代码,但是我的按钮被放置在页面的中间而不是在ActoBar中。p> 下面是代码
Animation animation = new RotateAnimation(0.0f, 360.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
animation.setRepeatCount(-1);
animation.setDuration(2000);
创建动画
启动服务之前,请将动画附加到imageview,如下所示
((ImageView)findViewById(R.id.btn_refresh_assets)).setAnimation(animation);
服务何时结束
((ImageView)findViewById(R.id.btn_refresh_assets)).clearAnimation();
以这种方式,我的imageButton正在旋转,但当我将其背景设置为null(android:background=“@null”)时,动画就不会播放!!!你有什么建议吗???!!!