zoukankan      html  css  js  c++  java
  • 02-05Android学习进度报告五

          今天主要学习了关于Android 开发的关于进度条和拖动条的知识。

    主要学习了一些关于进度条的基本属性:

    • android:max:进度条的最大值
    • android:progress:进度条已完成进度值
    • android:progressDrawable:设置轨道对应的Drawable对象
    • android:indeterminate:如果设置成true,则进度条不精确显示进度
    • android:indeterminateDrawable:设置不显示进度的进度条的Drawable对象
    • android:indeterminateDuration:设置不精确显示进度的持续时间
    • android:secondaryProgress:二级进度条,类似于视频播放的一条是当前播放进度,一条是缓冲进度,前者通过progress属性进行设置!

    我们可以用Java代码开调用它们

    • getMax():返回这个进度条的范围的上限
    • getProgress():返回进度
    • getSecondaryProgress():返回次要进度
    • incrementProgressBy(int diff):指定增加的进度
    • isIndeterminate():指示进度条是否在不确定模式下
    • setIndeterminate(boolean indeterminate):设置不确定模式下

    例如下面代码:

    <LinearLayout 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:orientation="vertical"
        tools:context=".MainActivity">
    
        <!-- 系统提供的圆形进度条,依次是大中小 -->
    
        <ProgressBar
            style="@android:style/Widget.ProgressBar.Small"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
        <ProgressBar
            style="@android:style/Widget.ProgressBar.Large"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
        <!--系统提供的水平进度条-->
        <ProgressBar
            style="@android:style/Widget.ProgressBar.Horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:max="100"
            android:progress="18" />
    
        <ProgressBar
            style="@android:style/Widget.ProgressBar.Horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:indeterminate="true" />
    
    </LinearLayout>

    然后来看拖动条的一些属性:

    android:max="100" //滑动条的最大值

    android:progress="60" //滑动条的当前值

    android:secondaryProgress="70" //二级滑动条的进度

    android:thumb = "@mipmap/sb_icon" //滑块的drawable

    onProgressChanged:进度发生改变时会触发

    onStartTrackingTouch:按住SeekBar时会触发

    onStopTrackingTouch:放开SeekBar时触发

    实例代码如下:

    public class MainActivity extends AppCompatActivity {
    
        private SeekBar sb_normal;
        private TextView txt_cur;
        private Context mContext;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            mContext = MainActivity.this;
            bindViews();
        }
    
        private void bindViews() {
            sb_normal = (SeekBar) findViewById(R.id.sb_normal);
            txt_cur = (TextView) findViewById(R.id.txt_cur);
            sb_normal.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    txt_cur.setText("当前进度值:" + progress + "  / 100 ");
                }
    
                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                    Toast.makeText(mContext, "触碰SeekBar", Toast.LENGTH_SHORT).show();
                }
    
                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                    Toast.makeText(mContext, "放开SeekBar", Toast.LENGTH_SHORT).show();
                }
            });
        }
    }
  • 相关阅读:
    批量替换文本的工具
    wcf异常显示错误到客户端
    文件以二进制存入数据库和从数据库读取二进制文件
    关于关系数据库的范式
    对于挑战书上的很久之前都看不懂的DP看懂的突破
    操作系统概念
    关于P,V操作理解的突破,关于并发设计与并行
    关于快速沃尔什变换
    我觉得我应该养成经常翻收藏夹的习惯
    目前我的思考模式
  • 原文地址:https://www.cnblogs.com/yang2000/p/12321736.html
Copyright © 2011-2022 走看看