本文主要是介绍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">
<SeekBarandroid: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;@Overridepublicvoid 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">
<RatingBarandroid: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;@Overridepublicvoid onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);ratingBar=(RatingBar)findViewById(R.id.ratingbarld);ratingBar.setOnRatingBarChangeListener(newRatingBarListener());}private class RatingBarListener implementsRatingBar.OnRatingBarChangeListener{@Overridepublicvoid onRatingChanged(RatingBar ratingBar, float rating,booleanfromUser) {System.out.println("rating-->"+rating);}}
}
但是我们一般想把RatingBar装饰的更好看,想把更好看的图片用来替换系统默认的图片,那么应该怎么改呢?
这篇关于Android 控件seekbar进度条、ratingbar星星平分条的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!