• SeekBar的基本使用方法


    a)         什么是SeekBar

    b)         使用SeekBar的步骤:

                                           i.              在布局文件当中声明SeekBar: <SekBar android:id=”@+id/seekbarld” android:layout_width=”fill_parent” android:layout_height=”wrap_content”/>

                                         ii.              定义一个OnSeekBarChangeListener: private class SeekBarListener implements SeekBar.OnSeekBarChangeListener{public void onProgressChanged(SeekBar seekBar,int progress,Boolean fromUser){System.out.println(progress);} public void onStartTrackingTouch(SeekBar seekBar){System.out.println(“start:=>”+seekBar.getProgress());} public void onStopTrackingTouch(SeekBar seekBar){System.out.println(“begin:=>”+seekBar.getProgress());}}

                                        iii.              SeekBar绑定监听器: seekBarSetOnSeekBarChangeListener(new SeekBarListener());

    案例项目:

    main.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/hello"
        />
        <SeekBar
         android:id="@+id/seekBarId"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         />
    </LinearLayout>
    SeekBarJsd.java:

    package com.jsd;

    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.SeekBar;

    /**
     * SeekBar Progress
     * @author Administrator
     *
     */
    public class SeekBarJsd extends Activity {
      
     private SeekBar seekBar = null;
     
     /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            
            seekBar = (SeekBar) findViewById(R.id.seekBarId);
            //设置该进度条的最大值,默认情况下为O
            seekBar.setMax(100);
            seekBar.setOnSeekBarChangeListener(seekBarListener);
        }
        
        /**
         * SeekBarListener 
         * 定义一个监听器,该监听器负责监听进度条进度的改变
         */
        private SeekBar.OnSeekBarChangeListener seekBarListener = new SeekBar.OnSeekBarChangeListener() {
      
         /**
          * 当用户结束对滑块滑动时,调用该方法
          */
      public void onStopTrackingTouch(SeekBar seekBar) {
       // TODO Auto-generated method stub
       System.out.println("stop: > "+seekBar.getProgress());
      }
      
      /**
       * 当用户开始滑动滑块时调用该方法
       */
      public void onStartTrackingTouch(SeekBar seekBar) {
       // TODO Auto-generated method stub
       System.out.println("start: => "+seekBar.getProgress());
      }
      
      /**
       * 当进度条发生变化时调用该方法
       */
      public void onProgressChanged(SeekBar seekBar, int progress,
        boolean fromUser) {
       // TODO Auto-generated method stub
       System.out.println(progress);
      }
     }

    图:
    }tu

  • 相关阅读:
    Python3全栈学习目录
    五句话搞定javavscript作用域
    Python线程池
    luogu4016 负载平衡问题
    luogu2756 飞行员配对方案问题
    luogu1251 餐巾计划问题
    luogu3386 【模板】二分图匹配 匈牙利算法 hdu2063 过山车 dinic
    luogu3381 【模板】最小费用最大流
    luogu3376 【模板】网络最大流 dinic
    luogu2740 [USACO4.2]草地排水Drainage Ditches 最大流EK
  • 原文地址:https://www.cnblogs.com/Gaojiecai/p/2181867.html
Copyright © 2020-2023  润新知