1. 程式人生 > >手機殺毒進度條特效

手機殺毒進度條特效

eight infinite start img drawable animation odin @+ ide

技術分享圖片





public
class MainActivity extends Activity { private ImageView iv_main_scan; private TextView tv_main_scan; private ProgressBar pb_main_scan; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv_main_scan
= (ImageView) findViewById(R.id.iv_main_scan); tv_main_scan = (TextView) findViewById(R.id.tv_main_scan); pb_main_scan = (ProgressBar) findViewById(R.id.pb_main_scan); //1. 顯示掃描動畫 showScanAnimation(); //2. 掃描,並顯示掃描進度 scan(); } /**
* 掃描,並顯示掃描進度 */ private void scan() { //啟動異步任務做 new AsyncTask<Void, Void, Void>() { //1. 主線程, 顯示提示視圖 protected void onPreExecute() { tv_main_scan.setText("手機殺毒引擎正在掃描中..."); } //2. 分線程, 做長時間的工作(掃描應用)
@Override protected Void doInBackground(Void... params) { int appCount = 60; //設置進度條的最大值 pb_main_scan.setMax(appCount); for(int i=0;i<appCount;i++) { SystemClock.sleep(40); //掃描完成一個 //發布進度 publishProgress(); } return null; } //在主線程執行, 更新進度 protected void onProgressUpdate(Void[] values) { pb_main_scan.incrementProgressBy(1);//增加1 //pb_main_scan.setProgress(pb_main_scan.getProgress()+1); } //3. 主線程, 更新界面 protected void onPostExecute(Void result) { //隱藏進度條 pb_main_scan.setVisibility(View.GONE); //更新文本 tv_main_scan.setText("掃描完成, 未發現病毒應用, 請放心使用!"); //停止掃描動畫 iv_main_scan.clearAnimation(); } }.execute(); } /** * 顯示掃描動畫 * iv_main_scan的旋轉動畫 */ private void showScanAnimation() { //創建動畫對象 RotateAnimation animation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); //設置 animation.setDuration(1000); animation.setRepeatCount(Animation.INFINITE); animation.setInterpolator(new LinearInterpolator()); //啟動 iv_main_scan.startAnimation(animation); } }
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="手機殺毒" 
        android:background="#FFCFCE"
        android:textSize="25sp"
        android:gravity="center"
        android:padding="5dp"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent" 
            android:background="@drawable/ic_scanner_malware">

            <ImageView
                android:id="@+id/iv_main_scan"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/act_scanning_03" />

        </FrameLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" 
            android:gravity="center_vertical"
            android:layout_marginLeft="10dp">

            <TextView
                android:id="@+id/tv_main_scan"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="TextView" />

            <ProgressBar
                android:id="@+id/pb_main_scan"
                style="?android:attr/progressBarStyleHorizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" 
                android:progressDrawable="@drawable/my_progress"/>

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

my_progress.xml

<?
xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 背景圖片 --> <item android:id="@android:id/background" android:drawable="@drawable/security_progress_bg"> </item> <!-- 進度圖片 --> <item android:id="@android:id/progress" android:drawable="@drawable/security_progress"> </item> </layer-list>

手機殺毒進度條特效