点击(此处)折叠或打开
-
<?xml version="1.0" encoding="utf-8"?>
-
<LinearLayout ? 线型布局管理器
-
xmlns:android=""
-
android:id="@+id/MyLayout" ? 布局管理器ID
-
android:orientation="vertical" ? 所有组件垂直摆放
-
android:layout_width="fill_parent" ? 布局管理器宽度为屏幕宽度
-
android:layout_height="fill_parent"> ? 布局管理器高度为屏幕高度
-
<RatingBar ? 定义评分组件
-
android:numStars="5" ? 有5颗评分星
-
android:stepSize="0.5" ? 每次评分步长为0.5
-
android:isIndicator="false" ? 用户可以操作
-
android:id="@+id/ratingbarA" ? 组件ID,程序中使用
-
android:layout_width="wrap_content" ? 组件宽度为屏幕宽度
-
android:layout_height="wrap_content"/> ? 组件高度为显示高度
-
<RatingBar ? 定义评分组件
-
android:numStars="5" ? 有5颗评分星
-
android:rating="3" ? 默认的分数
-
android:isIndicator="true" ? 用户不可操作
-
android:id="@+id/ratingbarB" ? 组件ID,程序中使用
-
android:layout_width="wrap_content" ? 组件宽度为屏幕宽度
-
android:layout_height="wrap_content"/> ? 组件高度为显示高度
-
<TextView ? 文本显示框
-
android:id="@+id/text" ? 组件ID,程序中使用
-
android:layout_width="fill_parent" ? 组件宽度为屏幕宽度
-
android:layout_height="wrap_content"/> ? 组件高度为屏幕高度
- </LinearLayout>
点击(此处)折叠或打开
-
public class MyRatingBarDemo extends Activity {
-
private RatingBar ratingBarA = null; // 定义评分组件
-
private TextView text = null; // 文本显示组件
-
@Override
-
public void onCreate(Bundle savedInstanceState) {
-
super.onCreate(savedInstanceState);
-
super.setContentView(R.layout.main);
-
this.ratingBarA = (RatingBar) super.findViewById(R.id.ratingbarA) ;
-
this.text = (TextView) super.findViewById(R.id.text) ;// 取得组件
-
this.ratingBarA.setOnRatingBarChangeListener(
-
new OnRatingBarChangeListenerImpl()); // 设置监听
-
}
-
private class OnRatingBarChangeListenerImpl implements
-
RatingBar.OnRatingBarChangeListener {
-
@Override
-
public void onRatingChanged(RatingBar ratingBar, float rating,
-
boolean fromUser) {
-
MyRatingBarDemo.this.text.append("*** 当前值(Rating):"
-
+ ratingBar.getRating() + ",增长步长:"
-
+ ratingBar.getStepSize() + "\n"); // 增加文本显示
-
}
-
}
- }
020706_评分组件:RatingBar.ppt