android带滑块的进度条,Android进度条(ProgressBar)拖动条(SeekBar)星级滑块(RatingBar)的例子...

1、string.xml文件

当前进度:%s

当前进度:20%

2、布局文件 bar.xml

android:orientation="vertical"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:padding="10dip">

android:id="@+id/textprogress"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_margin="10dip"

android:layout_gravity="center_horizontal"

android:text="@string/progress_o"/>

android:id="@+id/progress"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_margin="10dip"

android:max="100"

android:progress="20"

style="@android:style/Widget.ProgressBar.Horizontal" />

android:id="@+id/seek"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_margin="10dip"

android:max="100"

android:progress="20"/>

android:id="@+id/rating"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_margin="10dip"

android:max="5"

android:rating="1"/>

3、Activity文件 BarDemo.java

import android.app.Activity;

import android.os.Bundle;

import android.widget.ProgressBar;

import android.widget.RatingBar;

import android.widget.SeekBar;

import android.widget.TextView;

import android.widget.Toast;

import com.kf.samples5.R;

public class BarDemo extends Activity {

private final float MAX = 100f;

private final int RATING = 5;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.bar);

SeekBar seek = (SeekBar)findViewById(R.id.seek);

seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

@Override

public void onStopTrackingTouch(SeekBar seekBar) {

Toast.makeText(BarDemo.this, "StopTouch", Toast.LENGTH_SHORT).show();

}

@Override

public void onStartTrackingTouch(SeekBar seekBar) {

Toast.makeText(BarDemo.this, "StartTouch", Toast.LENGTH_SHORT).show();

}

@Override

public void onProgressChanged(SeekBar seekBar, int progress,

boolean fromUser) {

if(fromUser){

TextView textView = (TextView)findViewById(R.id.textprogress);

textView.setText(String.format(getString(R.string.progress), progress+"%"));

ProgressBar pBar = (ProgressBar)findViewById(R.id.progress);

pBar.setProgress(progress);

RatingBar rBar = (RatingBar)findViewById(R.id.rating);

rBar.setRating(progress/MAX*RATING);

}

}

});

RatingBar rBar = (RatingBar)findViewById(R.id.rating);

rBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {

@Override

public void onRatingChanged(RatingBar ratingBar, float rating,

boolean fromUser) {

if(fromUser){

TextView textView = (TextView)findViewById(R.id.textprogress);

textView.setText(String.format(getString(R.string.progress), (int)(rating*MAX/RATING)+"%"));

ProgressBar pBar = (ProgressBar)findViewById(R.id.progress);

pBar.setProgress((int) (rating*MAX/RATING));

SeekBar sBar = (SeekBar)findViewById(R.id.seek);

sBar.setProgress((int) (rating*MAX/RATING));

}

}

});

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值