1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 xmlns:tools="http://schemas.android.com/tools"
4 android:layout_width="match_parent"
5 android:layout_height="match_parent"
6 tools:context="com.example.administrator.android.TestActivity4"
7 android:orientation="vertical">
8 <!--进度条-->
9 <ProgressBar
10 android:layout_width="match_parent"
11 android:layout_height="wrap_content"
12 style="?android:attr/progressBarStyleHorizontal"
13 android:progress="30"
14 android:secondaryProgress="67"
15 android:max="100"
16 android:id="@+id/pb_1"/>
17 <!-- 旋转进度条-->
18 <ProgressBar
19 android:layout_width="match_parent"
20 android:layout_height="wrap_content"
21 style="?android:attr/progressBarStyleLarge"
22 android:id="@+id/pb_2"
23 android:visibility="gone"/>
24 <!-- 可拖动进度条-->
25 <SeekBar
26 android:layout_width="match_parent"
27 android:layout_height="wrap_content"
28 android:progress="0"
29 android:secondaryProgress="0"
30 android:max="80"
31 android:id="@+id/se_1"/>
32 <!--星级进度条-->
33 <RatingBar
34 android:layout_width="match_parent"
35 android:layout_height="wrap_content"
36 android:numStars="10"
37 android:rating="5.5"
38 android:isIndicator="true"/>
39 </LinearLayout>
1 package com.example.administrator.android;
2
3 import android.app.AlertDialog;
4 import android.support.v7.app.AppCompatActivity;
5 import android.os.Bundle;
6 import android.util.Log;
7 import android.view.View;
8 import android.widget.ProgressBar;
9 import android.widget.SeekBar;
10 import android.widget.Toast;
11
12 public class TestActivity4 extends AppCompatActivity {
13 SeekBar se_1;
14 ProgressBar pb_1;
15 ProgressBar pb_2;
16 @Override
17 protected void onCreate(Bundle savedInstanceState) {
18 super.onCreate(savedInstanceState);
19 setContentView(R.layout.activity_test4);
20
21 se_1 = (SeekBar)findViewById(R.id.se_1);
22 pb_1 = (ProgressBar)findViewById(R.id.pb_1);
23 pb_2 = (ProgressBar)findViewById(R.id.pb_2);
24
25 se_1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
26 // 进度改变触发
27 @Override
28 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
29 //进度条1的进度值
30 pb_1.setProgress(progress);
31 //判断是否达到最大值
32 if (progress==se_1.getMax())
33 {
34 pb_2.setVisibility(View.INVISIBLE); //不显示 但位置仍然保留
35 }
36 else
37 {
38 pb_2.setVisibility(View.VISIBLE);
39 }
40 // 只要progress变化就被触发
41 // Toast.makeText(TestActivity4.this, "当前进度 = "+progress, Toast.LENGTH_SHORT).show();
42 }
43 // 开始拖动
44 @Override
45 public void onStartTrackingTouch(SeekBar seekBar) {
46
47 Log.e("TAG","进度条开始拖动");
48 }
49 // 结束拖动
50 @Override
51 public void onStopTrackingTouch(SeekBar seekBar) {
52 Log.e("TAG","进度条停止拖动");
53 }
54 });
55 }
56 }
1 <?xml version="1.0" encoding="utf-8"?>
2 <manifest xmlns:andro
3 package="com.example.administrator.android">
4
5 <application
6 android:allowBackup="true"
7 android:icon="@mipmap/ic_launcher"
8 android:label="@string/app_name"
9 android:supportsRtl="true"
10 android:theme="@style/AppTheme">
11 <activity android:name=".MainActivity">
12 </activity>
13 <activity android:name=".TestActivity4">
14 <intent-filter>
15 <action android:name="android.intent.action.MAIN" />
16 <category android:name="android.intent.category.LAUNCHER" />
17 </intent-filter>
18 </activity>
19 </application>
20
21 </manifest>