安卓開發 一個比較炫的進度條
阿新 • • 發佈:2019-02-02
藉助了一個Library 感覺還是挺好看的一個進度條
MainActivity的程式碼:
public class MainActivity extends AppCompatActivity { private RoundProgressBarWidthNumber mRoundProgressBar; private HorizontalProgressBarWithNumber mProgressBar; private static final int MSG_PROGRESS_UPDATE = 0x110; private Handler mHandler= new Handler() { public void handleMessage(android.os.Message msg) { int progress = mProgressBar.getProgress(); int roundProgress = mRoundProgressBar.getProgress(); mProgressBar.setProgress(++progress); mRoundProgressBar.setProgress(++roundProgress); if (progress >= 100) { mHandler.removeMessages(MSG_PROGRESS_UPDATE); } mHandler.sendEmptyMessageDelayed(MSG_PROGRESS_UPDATE, 100); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mProgressBar= (HorizontalProgressBarWithNumber) findViewById(R.id.id_progressbar01); mRoundProgressBar = (RoundProgressBarWidthNumber) findViewById(R.id.id_progress02); mHandler.sendEmptyMessage(MSG_PROGRESS_UPDATE); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } }
xml的程式碼:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:zhy="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="25dp" > <com.zhy.view.HorizontalProgressBarWithNumber android:id="@+id/id_progressbar01" android:layout_width="300dp" android:layout_height="wrap_content" android:layout_marginTop="50dip" android:padding="5dp" /> <com.zhy.view.HorizontalProgressBarWithNumber android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="50dip" android:padding="5dp" android:progress="10" zhy:progress_text_color="#ff2903FC" zhy:progress_unreached_color="#ffBCB4E8" /> <com.zhy.view.HorizontalProgressBarWithNumber android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="50dip" android:progress="30" zhy:progress_text_color="#ff03F793" zhy:progress_text_size="30dp" zhy:progress_unreached_color="#ffAFF2D6" /> <com.zhy.view.HorizontalProgressBarWithNumber android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="50dip" android:padding="5dp" android:progress="50" zhy:progress_text_color="#ffF53B03" zhy:progress_unreached_color="#ffF7C6B7" /> <com.zhy.view.RoundProgressBarWidthNumber android:id="@+id/id_progress02" android:layout_width="match_parent" android:layout_height="100dp" android:layout_marginTop="50dip" android:progress="30" /> <com.zhy.view.RoundProgressBarWidthNumber android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="50dip" android:padding="5dp" android:progress="50" zhy:progress_reached_bar_height="20dp" zhy:progress_text_color="#ffF53B03" zhy:radius="60dp" /> <com.zhy.view.RoundProgressBarWidthNumber android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="50dip" android:padding="15dp" android:progress="70" zhy:progress_text_color="#ff2903FC" zhy:progress_text_size="30sp" zhy:progress_unreached_color="#ffBCB4E8" zhy:radius="80dp" /> <com.zhy.view.HorizontalProgressBarWithNumber android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="50dip" android:padding="5dp" android:progress="70" zhy:progress_reached_bar_height="20dp" zhy:progress_text_color="#ffF53B03" zhy:progress_unreached_color="#00F7C6B7" /> </LinearLayout> </ScrollView>
很明顯大多是要用到Library來實現的,這個好處也是能非常簡單集合這個進度條
效果圖: