android 最簡單的方式實現旋轉進度條
阿新 • • 發佈:2019-01-01
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">先看效果圖:</span>
要達到這樣的效果,很簡單,其原理就是將用ImageView顯示一張圖片,然後給ImageView新增圍繞中心旋轉的的動畫即可,主要程式碼如下:
</pre><pre name="code" class="html"><ImageView android:id="@+id/iv_pre_loading" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/pre_loading" />
其中drawable/pre_loading 就是旋轉的圖片,png格式就行!
在Activity裡面設定旋轉動畫即可:
Animation mRotateAnimation = new RotateAnimation(0.0f, 720.0f, Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF, 0.5f); mRotateAnimation.setFillAfter(true); mRotateAnimation.setInterpolator(new LinearInterpolator()); mRotateAnimation.setDuration(1200); mRotateAnimation.setRepeatCount(Animation.INFINITE); mRotateAnimation.setRepeatMode(Animation.RESTART); findViewById(R.id.iv_pre_loading).setAnimation(mRotateAnimation);
這樣就完成了!可以說,實現這樣的想過很簡單。