Android:SeekBar和RatingBar控件

SeekBar的创建(可滑动的)

1、在布局文件中声明 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="@string/hello"
    />
   
<SeekBar android:id="@+id/seekBar"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"/>
	
	
</LinearLayout>

2、 定义一个OnSeekBarChangeListener:监听器:

3、为SeekBar设置监听器

public class HelloBarActivity 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.seekBar)	;
        //设置该进度条的最大值
        seekBar.setMax(100);
        seekBar.setOnSeekBarChangeListener(new SeekBarListener());
    }
    //定义一个监听器,该监听器负责监听进度条状态的改变
    private class SeekBarListener implements SeekBar.OnSeekBarChangeListener{
    	//当进度条的进度发生变化时,会调用该方法
		@Override
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
			//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的创建(评级进度)

1、在布局文件中声明 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>
2、定义 一个RatingBar.OnRationBarChangeListener监听器()
3、为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);
		}
    }
}
评级

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT人.阿标

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值