• SeekBar和RatingBar的基本使用方法


    SeekBar:

    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="测试SeekBar"
        />
    <SeekBar
    	android:id="@+id/seekbarId"
    	android:layout_width="fill_parent"
    	android:layout_height="wrap_content"
    	/>
        
    </LinearLayout>
    

     MainActivity.java:

    package mars.seekbar;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.SeekBar;
    
    public class MainActivity extends Activity {
        /** Called when the activity is first created. */
    	private SeekBar seekBar = null;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            seekBar = (SeekBar)findViewById(R.id.seekbarId)	;
            //设置该进度条的最大值
            seekBar.setMax(100);
            seekBar.setOnSeekBarChangeListener(new SeekBarListener());
        }
        //定义一个监听器,该监听器负责监听进度条状态的改变
        private class SeekBarListener implements SeekBar.OnSeekBarChangeListener{
        	//当进度条的进度发生变化时,会调用该方法
    		@Override
    		public void onProgressChanged(SeekBar seekBar, int progress,
    				boolean fromUser) {
    			System.out.println(progress);
    		}
    		//当用户开始滑动滑块时,调用该方法
    		@Override
    		public void onStartTrackingTouch(SeekBar seekBar) {
    			System.out.println("start--->" + seekBar.getProgress());
    		}
    		//当用户结束对滑块的滑动时,调用该方法
    		@Override
    		public void onStopTrackingTouch(SeekBar seekBar) {
    			System.out.println("stop--->" + seekBar.getProgress());
    		}
        	
        }
    }
    

     RatingBar:

    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"
        />
    <RatingBar
    	android:id="@+id/ratingbarId"
    	android:layout_height="wrap_content"
    	android:layout_width="wrap_content"
    	android:numStars="5"
    	android:stepSize="1.0"
    	/>
    </LinearLayout>
    

     MainActivity.java:

    package mars.ratingbar;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.RatingBar;
    
    public class MainActivity extends Activity {
        /** Called when the activity is first created. */
    	private RatingBar ratingBar = null;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            ratingBar = (RatingBar)findViewById(R.id.ratingbarId);
            ratingBar.setOnRatingBarChangeListener(new RatingBarListener());
        }
        
        private class RatingBarListener implements RatingBar.OnRatingBarChangeListener{
    
    		@Override
    		public void onRatingChanged(RatingBar ratingBar, float rating,
    				boolean fromUser) {
    			System.out.println("rating--->" + rating);
    		}
        }
    }
    

     如下图:

  • 相关阅读:
    JAVA课程作业01
    《大道至简》第二章读后感
    《大道至简》第一章读后感
    制作Linux镜像,将腾讯云服务器系统制成镜像
    postman数据驱动
    Navicat Premium 连接Oracle数据库报错 instant Client LIght : unsupported server charcter ser ZHS16GBK
    查看python位数
    AutoItLibrary安装过程中遇到的坑
    hyrobot使用
    有这样一道智力题:“某商店规定:三个空汽水瓶
  • 原文地址:https://www.cnblogs.com/leihupqrst/p/3216144.html
Copyright © 2020-2023  润新知