Android 控件seekbar进度条、ratingbar星星平分条

Android 控件seekbar、ratingbar

1、Seekbar就是一个进度条;可拖动可改变;

拖动后:

原代码如下:

布局文件:

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

JAVA代码:

package lili.seekbar; import android.app.Activity; import android.os.Bundle; import android.widget.SeekBar; importandroid.widget.SeekBar.OnSeekBarChangeListener; public class SeekBarActivity extendsActivity { /**Called when the activity is first created. */ privateSeekBar seekBar = null; @Override publicvoid onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //绑定控件 seekBar= (SeekBar) findViewById(R.id.seekbarld); //设置进度条条的最大值 seekBar.setMax(100); //添加监听器 seekBar.setOnSeekBarChangeListener(newSeekBarListener()); } //一个监听器,该监听器负责监听进度条状态 的改变 privateclass SeekBarListener implements OnSeekBarChangeListener { //当进度条的进度发生 变化 时,会调用 该 方法 publicvoid onProgressChanged(SeekBar seekBar, int progress, booleanfromUser) { System.out.println(progress); } publicvoid onStartTrackingTouch(SeekBar seekBar) { System.out.println("start->"+ seekBar.getProgress()); } publicvoid onStopTrackingTouch(SeekBar seekBar) { System.out.println("stop->"+ seekBar.getProgress()); } } }

2、Ratingbar是平分条;星星表示

点击星星后:

原码:

布局文件:

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

JAVA文件:

package lili.ratingbar; import android.app.Activity; import android.os.Bundle; import android.widget.RatingBar; public class RatingBarActivity extends Activity{ /**Called when the activity is first created. */ privateRatingBar ratingBar=null; @Override publicvoid onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ratingBar=(RatingBar)findViewById(R.id.ratingbarld); ratingBar.setOnRatingBarChangeListener(newRatingBarListener()); } private class RatingBarListener implementsRatingBar.OnRatingBarChangeListener{ @Override publicvoid onRatingChanged(RatingBar ratingBar, float rating, booleanfromUser) { System.out.println("rating-->"+rating); } } }

但是我们一般想把RatingBar装饰的更好看,想把更好看的图片用来替换系统默认的图片,那么应该怎么改呢?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值