Android--进度条

ProgressBar//进度条
  • 默认是圆形的进度条
  • ProgressBar
  • void setProgress(int Progress):设置当前进度
  • int getProgress():得到当前进度
  • void setMax(int max):设置最大进度
  • int getMax():设置或得到最大进度
  • View
  • void setVisibility(int visibility):设置视图的可见性
  • View.VISIBLE:标识可见
  • View.INVISIBLE:标识不可见,但占屏幕空间
  • View.GONE:表示不可见,也不占屏幕空间
SeekBar:可手动滑动的进度条:
  • setOnSeekBarChangeListener(OnSeekBarChangeListenter l):设置改变的监听
  • OnseekBarChangeListener:
  • onProgressChanged(SeekBar seekBar,int progress,boolean fromUser):改变进度
  • onStartTrackingTouth():按下滑杆
  • onStopTrackingTouth(SeekBar seekBar):从滑杆离开

xml代码:

   <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="center"
            android:id="@+id/ll_progress">
            <ProgressBar
                style="?android:attr/progressBarStyle"
                android:layout_width="100dp"
                android:layout_height="wrap_content" />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="正在加载中...."/>

        </LinearLayout>

        <ProgressBar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            style="?android:progressBarStyleHorizontal"
            android:progress="30"
            android:id="@+id/pb_progress"/>

        <SeekBar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/sb_progress"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="功能需求:\n1,滑动下面的滑杆后,上面的进度条会同步\n2,滑动到最大值后,最上面的进度条会消失"/>
    </LinearLayout>

java代码:

public class MainActivity extends AppCompatActivity {

    private LinearLayout ll_progress;
    private ProgressBar pb_proress;
    private SeekBar sb_progress;
    private boolean ptf;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ll_progress = (LinearLayout) findViewById(R.id.ll_progress);
        pb_proress = (ProgressBar) findViewById(R.id.pb_progress);
        sb_progress = (SeekBar) findViewById(R.id.sb_progress);

        sb_progress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                //改变进度
                Log.e("TAG","改变进度");
                //得到seekBar进度
                int len=seekBar.getProgress();
                //设置为ProgressBar进度
                pb_proress.setProgress(len);
                if(len==100){
                    ll_progress.setVisibility(View.GONE);
                    ptf=false;
                }else{
                    if(ptf==false){
                        ptf=true;
                        ll_progress.setVisibility(View.VISIBLE);
                    }
                }
            }
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                //按下滑杆
                Log.e("TAG","按下滑杆");
            }
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                //离开滑杆
                Log.e("TAG","离开滑杆");
            }
        });
    }
}

发布了49 篇原创文章 · 获赞 0 · 访问量 1355

猜你喜欢

转载自blog.csdn.net/qq_43616001/article/details/104094558