标签:
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 android:paddingBottom="16dp" 7 android:paddingLeft="16dp" 8 android:paddingRight="16dp" 9 android:paddingTop="16dp" 10 tools:context="com.example.wang.testapp2.TestActivity4" 11 android:orientation="vertical"> 12 13 <ProgressBar 14 android:layout_width="match_parent" 15 android:layout_height="wrap_content" 16 style="?android:attr/progressBarStyleHorizontal" 17 android:progress="40" 18 android:secondaryProgress="50" 19 android:max="80" 20 android:id="@+id/pb_1"/> 21 22 <ProgressBar 23 android:layout_width="match_parent" 24 android:layout_height="wrap_content" 25 style="?android:attr/progressBarStyleLarge" 26 android:id="@+id/pb_2"/> 27 28 <SeekBar 29 android:layout_width="match_parent" 30 android:layout_height="wrap_content" 31 android:progress="40" 32 android:max="80" 33 android:secondaryProgress="50" 34 android:id="@+id/se_1"/> 35 36 </LinearLayout>
1 package com.example.wang.testapp2; 2 3 import android.app.Activity; 4 import android.app.AlertDialog; 5 import android.support.v7.app.AppCompatActivity; 6 import android.os.Bundle; 7 import android.util.Log; 8 import android.view.View; 9 import android.widget.ImageView; 10 import android.widget.ProgressBar; 11 import android.widget.SeekBar; 12 import android.widget.Toast; 13 14 public class TestActivity4 extends Activity { 15 16 ProgressBar pb_1; 17 ProgressBar pb_2; 18 SeekBar se_1; 19 20 @Override 21 protected void onCreate(Bundle savedInstanceState) { 22 super.onCreate(savedInstanceState); 23 setContentView(R.layout.activity_test4); 24 25 se_1=(SeekBar)findViewById(R.id.se_1); 26 pb_1=(ProgressBar)findViewById(R.id.pb_1); 27 pb_2=(ProgressBar)findViewById(R.id.pb_2); 28 29 se_1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 30 31 //进度变化触发 32 @Override 33 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 34 35 //设置进度条1的进度值 36 pb_1.setProgress(progress); 37 38 39 //判断是否达到最大值 40 if (progress == se_1.getMax()) 41 { 42 pb_2.setVisibility(View.INVISIBLE);//不显示但位置还保留 43 } 44 else 45 { 46 pb_2.setVisibility(View.VISIBLE); 47 } 48 49 //只要progress变化就被触发 50 51 // Toast.makeText(TestActivity4.this, "当前进度="+progress, Toast.LENGTH_SHORT).show(); 52 } 53 54 @Override 55 public void onStartTrackingTouch(SeekBar seekBar) { 56 57 Log.e("TAG", "进度条开始拖动"); 58 } 59 60 @Override 61 public void onStopTrackingTouch(SeekBar seekBar) { 62 63 Log.e("TAG", "进度条停止拖动"); 64 65 } 66 }); 67 68 } 69 }
标签:
原文地址:http://www.cnblogs.com/arxk/p/5479611.html