zoukankan      html  css  js  c++  java
  • 拖拽进度条(SeekBar)

    拖拽进度条(SeekBar)

    监听方法:setOnSeekBarChangeListener

    监听器:SeekBar.OnSeekBarChangeListener

    简单,直接上代码:

    1.Activity

    //拖拽进度条
    public class SeekBarActivity extends Activity {
        
        private Context context;
        private SeekBar seekBar;
        private TextView textView;
        
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.seek_bar);
            
            context = this;
            seekBar = (SeekBar)findViewById(R.id.seekBarId);
            textView = (TextView)findViewById(R.id.textViewId);
            
            seekBar.setMax(100);
            
            seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
                //停止触摸
                public void onStopTrackingTouch(SeekBar seekBar) {
                    int progress = seekBar.getProgress();
                    Toast.makeText(context, "停止触摸", Toast.LENGTH_SHORT).show();
                }
                //开始触摸
                public void onStartTrackingTouch(SeekBar seekBar) {
                    Toast.makeText(context, "开始触摸", Toast.LENGTH_SHORT).show();
                }
                //拖动过程中
                public void onProgressChanged(SeekBar seekBar, int progress, 
                        boolean fromUser) {
                    textView.setText(progress+"/"+seekBar.getMax());
                }
            });
            
        }
    }

    2.xml布局文件

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="5dp" >
    <!-- 拖拽进度条 -->
        <SeekBar
            android:id="@+id/seekBarId"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    
        <TextView
            android:id="@+id/textViewId"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/seekBarId"
            android:layout_alignParentRight="true"
            android:text="0%" />
        
    </RelativeLayout>

    3.效果显示图

  • 相关阅读:
    thinkphp 3.2 服务器 session 设置时间周期失效问题 服务器是linux windows 上暂时没有发现此类问题
    php 不常见的开发模式
    js 里面的 call 方法 和 apply 方法
    PHP读取文件目录, 并显示需要的目录
    PHP 时间格式
    Python之旅.第三章.函数
    Python之旅.第三章.函数
    Python之旅.第三章.函数
    Python之旅.第三章.函数
    Python之旅.第三章.函数
  • 原文地址:https://www.cnblogs.com/wuziyue/p/5470839.html
Copyright © 2011-2022 走看看