AndroidGUI08:RatingBar的常用技巧
2011-05-12 12:46
274 查看
RatingBar
其实也是一种
ProgressBar
,它是
ProgressBar
的间接派生类,因此
ProgressBar
可以用的方法,
RatingBar
都可以用。
1.
在布局文件
(main.xml)
中,增加界面元素声明如下:
<?
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/ratebar"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:numStars
=
"5"
android:stepSize
=
"0.1"
/>
<
TextView
android:id
=
"@+id/tv_ratebar"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:text
=
""
/>
</
LinearLayout
>
2.
Activity
所对应的代码:
public
class
ControlRatingBar
extends
Activity
implements
OnRatingBarChangeListener
{
private
RatingBar
ratebar
;
@Override
public
void
onCreate(Bundle savedInstanceState)
{
super
.onCreate(savedInstanceState);
setContentView(R.layout.
main
);
ratebar
=
(RatingBar)findViewById(R.id.
ratebar
);
ratebar
.setOnRatingBarChangeListener(
this
);
}
public
void
onRatingChanged(RatingBar ratingBar,
float
rating,
boolean
fromUser)
{
((TextView)findViewById(R.id.
tv_ratebar
)).setText(
" "
+
rating);
}
}
运行结果
:
其实也是一种
ProgressBar
,它是
ProgressBar
的间接派生类,因此
ProgressBar
可以用的方法,
RatingBar
都可以用。
1.
在布局文件
(main.xml)
中,增加界面元素声明如下:
<?
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/ratebar"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:numStars
=
"5"
android:stepSize
=
"0.1"
/>
<
TextView
android:id
=
"@+id/tv_ratebar"
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:text
=
""
/>
</
LinearLayout
>
2.
Activity
所对应的代码:
public
class
ControlRatingBar
extends
Activity
implements
OnRatingBarChangeListener
{
private
RatingBar
ratebar
;
@Override
public
void
onCreate(Bundle savedInstanceState)
{
super
.onCreate(savedInstanceState);
setContentView(R.layout.
main
);
ratebar
=
(RatingBar)findViewById(R.id.
ratebar
);
ratebar
.setOnRatingBarChangeListener(
this
);
}
public
void
onRatingChanged(RatingBar ratingBar,
float
rating,
boolean
fromUser)
{
((TextView)findViewById(R.id.
tv_ratebar
)).setText(
" "
+
rating);
}
}
运行结果
:
相关文章推荐
- AndroidGUI02:EditText的常用技巧
- Android之编译打包apk时几个常用的技巧【转】
- Android ViewTreeObserver的常用技巧
- android开发技巧总结(68个常用用法)
- AndroidGUI02:EditText的常用技巧
- AndroidGUI14:各种Dialog常用技巧
- AndroidGUI17:Layout常用技巧
- android常用技巧
- Android常用技巧总结
- Android_编程规范与常用技巧
- AndroidGUI20:GridView常用技巧
- AndroidGUI01:TextView的常用技巧
- AndroidGUI03:Spinner的常用技巧
- 【Android】编程规范与常用技巧
- Android Spinner的常用技巧
- Android ViewTreeObserver的常用技巧
- AndroidGUI16:Theme常用技巧
- # AndroidStudio 常用工具和使用技巧(持续更新)
- AndroidGUI09:Chronometer(计时器)的常用技巧
- AndroidGUI03:Spinner的常用技巧