• 3.6bar控件


    ProcessBar:进度条

    SeekBar:拖动条

    RatingBar:评分控件

    界面:

    布局:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.liang.barliang.MainActivity">
    
        <ProgressBar
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/progressBar"
            android:layout_alignParentTop="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentEnd="true" />
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="download"
            android:id="@+id/button"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true" />
    
        <SeekBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/seekBar"
            android:layout_below="@+id/progressBar"
            android:layout_alignParentStart="true"
            android:layout_marginTop="52dp"
            android:layout_alignEnd="@+id/progressBar" />
    
        <RatingBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/ratingBar"
            android:layout_marginTop="52dp"
            android:layout_below="@+id/seekBar"
            android:layout_centerHorizontal="true" />
    </RelativeLayout>

    程序:

    import android.content.Intent;
    import android.os.AsyncTask;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    import android.widget.ProgressBar;
    import android.widget.RatingBar;
    import android.widget.SeekBar;
    import android.widget.Toast;
    
    public class MainActivity extends AppCompatActivity {
        private final static String TAG = "bar";
        private Button button;
        private ProgressBar progressBar;
        private SeekBar seekBar;
        private RatingBar ratingBar;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            button = (Button) this.findViewById(R.id.button);
            progressBar = (ProgressBar) this.findViewById(R.id.progressBar);
            seekBar = (SeekBar) this.findViewById(R.id.seekBar);
            ratingBar = (RatingBar) this.findViewById(R.id.ratingBar);
    
            progressBar.setMax(100);
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    new DownloadTask().execute();
                }
            });
    
            //
            seekBar.setMax(100);
            seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                 //实时变化的回调函数
                }
    
                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                //开始滚动的回调函数
                }
    
                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                    //滚动结束的回调函数
                    Toast.makeText(MainActivity.this, "Volume:" + seekBar.getProgress(), Toast.LENGTH_SHORT).show();
                }
            });
    
            //评分控件
            ratingBar.setNumStars(5);
            ratingBar.setMax(100);
            ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
                @Override
                public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                    Toast.makeText(MainActivity.this, "Stars:" + rating, Toast.LENGTH_SHORT).show();
                }
            });
        }
    
        //进度控件 下载实时更新
        class DownloadTask extends AsyncTask<Void, Integer, Void> {
    
            @Override
            protected void onProgressUpdate(Integer... values) {
                super.onProgressUpdate(values);
                progressBar.setProgress(values[0]);
            }
    
            @Override
            protected Void doInBackground(Void... params) {
                int i = 1;
                while (i <= 100) {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    Log.i(TAG, String.valueOf(i));
                    publishProgress(i);
                    i++;
                }
                return null;
            }
        }
    }
  • 相关阅读:
    [Python自学] day-10 (多进程、数据交互、进程锁、__main__、进程池、协程、gevent、简单爬虫、事件驱动异步IO、select poll epoll)
    [Python自学] day-9 (paramiko、SSH RSA、线程、GIL、互斥锁、信号量、事件、队列)
    [Python自学] day-8 (SocketServer)
    [Python自学] day-7 (静态方法、类方法、属性方法、类的其他、类的来源、反射、异常处理、socket)
    MyBatis学习 之 一、MyBatis简介与配置MyBatis+Spring+MySql
    深入浅出MyBatis-快速入门
    spring整合myBatis
    MyBatis入门学习(一)
    Mybatis中几个重要类
    ibatis源码分析
  • 原文地址:https://www.cnblogs.com/manusas/p/5614535.html
Copyright © 2020-2023  润新知