Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7563497
  • 博文数量: 961
  • 博客积分: 15795
  • 博客等级: 上将
  • 技术积分: 16612
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-07 14:23
文章分类

全部博文(961)

文章存档

2016年(1)

2015年(61)

2014年(41)

2013年(51)

2012年(235)

2011年(391)

2010年(181)

分类: Android平台

2015-11-23 11:15:58


点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout                ?    线型布局管理器
  3.     xmlns:android=""
  4.     android:id="@+id/MyLayout"            ?    布局管理器ID
  5.     android:orientation="vertical"         ?    所有组件垂直摆放
  6.     android:layout_width="fill_parent"        ?    布局管理器宽度为屏幕宽度
  7.     android:layout_height="fill_parent">        ?    布局管理器高度为屏幕高度
  8.     <RatingBar                ?    定义评分组件
  9.         android:numStars="5"            ?    有5颗评分星
  10.         android:stepSize="0.5"            ?    每次评分步长为0.5
  11.         android:isIndicator="false"        ?    用户可以操作
  12.         android:id="@+id/ratingbarA"        ?    组件ID,程序中使用
  13.         android:layout_width="wrap_content"        ?    组件宽度为屏幕宽度
  14.         android:layout_height="wrap_content"/>    ?    组件高度为显示高度
  15.     <RatingBar                ?    定义评分组件
  16.         android:numStars="5"            ?    有5颗评分星
  17.         android:rating="3"            ?    默认的分数
  18.         android:isIndicator="true"        ?    用户不可操作
  19.         android:id="@+id/ratingbarB"        ?    组件ID,程序中使用
  20.         android:layout_width="wrap_content"        ?    组件宽度为屏幕宽度
  21.         android:layout_height="wrap_content"/>    ?    组件高度为显示高度
  22.     <TextView                ?    文本显示框
  23.         android:id="@+id/text"            ?    组件ID,程序中使用
  24.         android:layout_width="fill_parent"        ?    组件宽度为屏幕宽度
  25.         android:layout_height="wrap_content"/>    ?    组件高度为屏幕高度
  26. </LinearLayout>

点击(此处)折叠或打开

  1. public class MyRatingBarDemo extends Activity {
  2.     private RatingBar ratingBarA = null;         // 定义评分组件
  3.     private TextView text = null;             // 文本显示组件
  4.     @Override
  5.     public void onCreate(Bundle savedInstanceState) {
  6.         super.onCreate(savedInstanceState);
  7.         super.setContentView(R.layout.main);
  8.         this.ratingBarA = (RatingBar) super.findViewById(R.id.ratingbarA) ;
  9.         this.text = (TextView) super.findViewById(R.id.text) ;// 取得组件
  10.         this.ratingBarA.setOnRatingBarChangeListener(
  11.                 new OnRatingBarChangeListenerImpl());        // 设置监听
  12.     }
  13.     private class OnRatingBarChangeListenerImpl implements
  14.             RatingBar.OnRatingBarChangeListener {
  15.         @Override
  16.         public void onRatingChanged(RatingBar ratingBar, float rating,
  17.                 boolean fromUser) {
  18.             MyRatingBarDemo.this.text.append("*** 当前值(Rating):"
  19.                     + ratingBar.getRating() + ",增长步长:"
  20.                     + ratingBar.getStepSize() + "\n"); // 增加文本显示
  21.         }
  22.     }
  23. }

020706_评分组件:RatingBar.ppt
阅读(1735) | 评论(0) | 转发(1) |
0

上一篇:拖动条:SeekBar

下一篇:Toast组件

给主人留下些什么吧!~~