예배 규칙서 찾다
android Manifest Manifest.permission Manifest.permission_group android.accessibilityservice AccessibilityService android.accounts Account android.app NotificationManager android.bluetooth BluetoothAdapter BluetoothClass BluetoothClass.Device BluetoothClass.Device.Major BluetoothClass.Service BluetoothDevice BluetoothServerSocket BluetoothSocket android.content SharedPreferences android.database.sqlite SQLiteCursorDriver SQLiteOpenHelper android.graphics Bitmap android.location LocationListener Geocoder GpsStatus GpsStatus.Listener GpsStatus.NmeaListener GpsSatellite android.media AudioFormat AsyncPlayer AudioRecord AudioRecord.OnRecordPositionUpdateListener ThumbnailUtils AudioManager android.net TrafficStats MailTo LocalSocket android.os AsyncTask AsyncTask.Status CountDownTimer Message MessageQueue HandlerThread android.text Html android.util JsonWriter android.view ContextMenu ContextMenu.ContextMenuInfo Display ViewManager View ViewStub ViewTreeObserver ViewParent WindowManager GestureDetector Gravity MenuInflater ScaleGestureDetector SoundEffectConstants android.view.inputmethod InputConnection InputMethod InputMethodSession BaseInputConnection InputMethodManager android.widget AbsListView AbsListView.LayoutParams AbsListView.OnScrollListener AbsListView.RecyclerListener AbsoluteLayout AbsoluteLayout.LayoutParams AbsSeekBar AbsSpinner AdapterView AdapterView.AdapterContextMenuInfo AdapterView.OnItemLongClickListener AdapterView.OnItemSelectedListener AdapterView.OnItemClickListener AnalogClock BaseAdapter BaseExpandableListAdapter Button CheckBox CheckedTextView Checkable Chronometer Chronometer.OnChronometerTickListener CompoundButton CompoundButton.OnCheckedChangeListener CursorAdapter CursorTreeAdapter DatePicker DatePicker.OnDateChangedListener DialerFilter DigitalClock EditText Filter Filter.FilterListener Filter.FilterResults ExpandableListAdapter ExpandableListView.OnChildClickListener ExpandableListView.OnGroupClickListener ExpandableListView.OnGroupCollapseListener ExpandableListView.OnGroupExpandListener Filterable Gallery Gallery.LayoutParams GridView GridLayout GridLayout.Alignment RadioGroup ImageView ImageView.ScaleType HorizontalScrollView ImageButton ImageSwitcher FilterQueryProvider ListAdapter ListView MediaController MultiAutoCompleteTextView MultiAutoCompleteTextView.CommaTokenizer MultiAutoCompleteTextView.Tokenizer QuickContactBadge RadioButton RatingBar RatingBar.OnRatingBarChangeListener RelativeLayout RemoteViews ResourceCursorAdapter ResourceCursorTreeAdapter Scroller ScrollView SearchView SearchView.OnCloseListener SearchView.OnQueryTextListener SearchView.OnSuggestionListener SeekBar SeekBar.OnSeekBarChangeListener SimpleAdapter SimpleAdapter.ViewBinder SimpleCursorAdapter SimpleCursorAdapter.CursorToStringConverter SimpleCursorAdapter.ViewBinder SimpleCursorTreeAdapter SimpleCursorTreeAdapter.ViewBinder SimpleExpandableListAdapter SlidingDrawer SlidingDrawer.OnDrawerCloseListener SlidingDrawer.OnDrawerOpenListener SlidingDrawer.OnDrawerScrollListener Spinner SpinnerAdapter WrapperListAdapter TabHost TabHost.TabSpec TextView TimePicker TimePicker.OnTimeChangedListener Toast TableLayout TableLayout.LayoutParams TableRow TableRow.LayoutParams TabWidget TextSwitcher ToggleButton TwoLineListItem VideoView ViewAnimator ViewFlipper ViewSwitcher ViewSwitcher.ViewFactory ZoomButtonsController ZoomButtonsController.OnZoomListener ZoomButton ZoomControls dalvik.system DexFile
문자


RatingBar

翻译人:wallace2010/madgoat

译者博客:http://madgoat.cn/

http://blog.csdn.net/springiscoming2008

版本:Android 2.2 r1

public classRatingBarextendsAbsSeekBar

java.lang.Object

android.view.View

android.widget.ProgressBar

android.widget.AbsSeekBar

android.widget.RatingBar

类概述

说明: C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\_T0)`TREGPTYW8572GPI3FW.jpg

RatingBar是基于SeekBarProgressBar的扩展,用星型来显示等级评定。使用RatingBar的默认大小时,用户可以触摸/拖动或使用键来设置评分,它有两种样式(小风格用ratingBarStyleSmall,大风格用ratingBarStyleIndicator),其中大的只适合指示,不适合于用户交互。

当使用可以支持用户交互的RatingBar时,无论将控件(widgets)放在它的左边还是右边都是不合适的。

只有当布局的宽被设置为wrap content时,设置的星星数量(通过函数setNumStars(int)或者在XML的布局文件中定义)将显示出来(如果设置为另一种布局宽的话,后果无法预知)。

次级进度一般不应该被修改,因为他仅仅是被当作星型部分内部的填充背景。

参见Form Stuff tutorial.

嵌套类

接口:RatingBar.OnRatingBarChangeListener

一个回调函数,当星级进度改变时修改客户端的星级。

XML属性

属性名称

描述

android:isIndicator

RatingBar是否是一个指示器(用户无法进行更改)

android:numStars

显示的星型数量必须是一个整形值,像“100”。

android:rating

默认的评分,必须是浮点类型,像“1.2”。

android:stepSize

评分的步长必须是浮点类型,像“1.2”。

公共方法

public int getNumStars ()

返回显示的星型数量

返回值

显示的星型数量

public RatingBar.OnRatingBarChangeListener getOnRatingBarChangeListener ()

返回值

监听器(可能为空)监听评分改变事件

public float getRating ()

获取当前的评分(填充的星型的数量)

返回值

当前的评分

public float getStepSize ()

获取评分条的步长

返回值

The step size.

步长

public boolean isIndicator ()

返回值

判断当前的评分条是否仅仅是一个指示器(注:即能否被修改)

public void setIsIndicator (boolean isIndicator)

设置当前的评分条是否仅仅是一个指示器(这样用户就不能进行修改操作了)

参数

isIndicator Bool值,是否是一个指示器

public synchronized void setMax (int max)

设置评分等级的范围,从0max

参数

max评分条最大范围。

public void setNumStars (int numStars)

设置显示的星型的数量。为了能够正常显示它们,建议将当前widget的布局宽度设置为wrap content

参数

numStars星型的数量

public void setOnRatingBarChangeListener (RatingBar.OnRatingBarChangeListener listener)

设置当评分等级发生改变时回调的监听器

参数

listener监听器

public void setRating (float rating)

设置分数(星型的数量)

参数

rating设置的分数

public void setStepSize (float stepSize)

设置当前评分条的步长(step size

参数

stepSize评分条的步进。例如:如果想要半个星星,它的值为0.5

受保护方法

protected synchronized voidonMeasure(int widthMeasureSpec, int heightMeasureSpec)

权衡viewcontent来决定它的宽度和高度的整齐。它被measure(int, int)调用并且应该被子类所覆盖,以便提供准确高效的布局测量。

规定:当覆盖这个方法的时候,你必须调用setMeasuredDimension(int, int)以便存储精确的视图的宽和高。如果不这样做的话将触发llegalStateException异常,被函数measure(int, int)抛出。调用父类onMeasure(int, int)是合理的。

尺寸的基本类的实现默认是背景大小,除非通过MeasureSpec允许大的尺寸。子类应该覆盖onMeasure(int, int)以便提供更好的布局大小。

如果这个方法被覆盖,子类应该负责确保标准的宽和高至少是视图的最小宽度和高度的值(分别为getSuggestedMinimumHeight()getSuggestedMinimumWidth()两方法)。

参数

widthMeasureSpec受主窗口支配的水平空间要求。这个需求通过View.MeasureSpec.进行编码。

heightMeasureSpec受主窗口支配的垂直空间要求。这个需求通过View.MeasureSpec.进行编码。

补充

文章链接

Android控件之RatingBar评分条

Android更换RatingBar图片

[Android学习指南]RatingBar评分条

示例代码(代码转载自Android手机开发者论坛

AndroidRatingBar.java

publicclassAndroidRatingBarextendsActivity {

@Override

publicvoidonCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

finalRatingBar ratingBar_Small = (RatingBar)findViewById(R.id.ratingbar_Small);

finalRatingBar ratingBar_Indicator = (RatingBar)findViewById(R.id.ratingbar_Indicator);

finalRatingBar ratingBar_default = (RatingBar)findViewById(R.id.ratingbar_default);

ratingBar_default.setOnRatingBarChangeListener(newRatingBar.OnRatingBarChangeListener(){

publicvoidonRatingChanged(RatingBar ratingBar,floatrating,

booleanfromUser) {

ratingBar_Small.setRating(rating);

ratingBar_Indicator.setRating(rating);

Toast.makeText(AndroidRatingBar.this,"rating:"+String.valueOf(rating),

Toast.LENGTH_LONG).show();

}});

}

}

main.xml

xmlversion="1.0"encoding="utf-8"?>

<LinearLayoutxmlns: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:layout_width="wrap_content"

android:layout_height="wrap_content"

style="?android:attr/ratingBarStyleIndicator"

android:id="@+id/ratingbar_Indicator"

/>

<RatingBar

android:layout_width="wrap_content"

android:layout_height="wrap_content"

style="?android:attr/ratingBarStyleSmall"

android:id="@+id/ratingbar_Small"

android:numStars="20"

/>

<RatingBar

android:layout_width="wrap_content"

android:layout_height="wrap_content"

style="?android:attr/ratingBarStyle"

android:id="@+id/ratingbar_default"

/>

LinearLayout>


이전 기사: 다음 기사: