其他分享
首页 > 其他分享> > Android--进度条

Android--进度条

作者:互联网

ProgressBar//进度条
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","离开滑杆");
            }
        });
    }
}

Boml.白顶 发布了48 篇原创文章 · 获赞 0 · 访问量 1275 私信 关注

标签:进度条,SeekBar,void,seekBar,int,progress,Android,View
来源: https://blog.csdn.net/qq_43616001/article/details/104094558