android 星级条和拖动条

来源:互联网 发布:房地产行业 知乎 编辑:程序博客网 时间:2024/04/27 23:03

拖动条:

<TextView    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:id="@+id/textView1"    android:text="当前值50"/><SeekBar    android:max="100"    android:progress="50"    android:layout_width="wrap_content"    android:layout_height="match_parent"    android:id="@+id/seekbar1"/>
SeekBar seekBar = (SeekBar) findViewById(R.id.seekbar1);result = (TextView) findViewById(R.id.textView1);seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {    @Override    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {        result.setText("当前值:"+progress);    }    @Override    public void onStartTrackingTouch(SeekBar seekBar) {        Toast.makeText(TestActivity.this,"开始滑动",Toast.LENGTH_LONG).show();    }    @Override    public void onStopTrackingTouch(SeekBar seekBar) {        Toast.makeText(TestActivity.this,"结束滑动",Toast.LENGTH_LONG).show();    }});


星级评分条:

<RatingBar    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:numStars="5"    android:rating="3.5"    android:isIndicator="true"    android:id="@+id/ratingbar1"/><Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="提交"    android:id="@+id/button1"/>
final RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingbar1);Button button = (Button) findViewById(R.id.button1);button.setOnClickListener(new View.OnClickListener() {    @Override    public void onClick(View v) {        int result = ratingBar.getProgress();//获取进度        float rating = ratingBar.getRating();//获取等级        float step = ratingBar.getStepSize();//获取每次最少要改变多少星级        Toast.makeText(TestActivity.this,"你得到了"+rating+"颗星",Toast.LENGTH_LONG).show();    }});

0 0
原创粉丝点击