借助了一个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来实现的,这个好处也是能非常简单集合这个进度条
效果图:
这个Demo的下载地址:https://github.com/Small-code-monkey/ProgressBarDemo