zoukankan      html  css  js  c++  java
  • RatingBar

    RatingBar和SeekBar,有相同的父类AbsSeekBar,有的xml属性和progressbar一样。

    使用起来很简单,RatingBar几个重要的XML属性如下:

                          android:isIndicator             设置星级评分条是否允许用户改变

            android:numStars             设置星星的数量,一般为5

            android:stepSize               设置一次拖动多少个星星,一般为0.5

            android:rating                   设置默认星级


    1.Activity

     1 package gdp.ratingbartest;
     2 
     3 import android.annotation.SuppressLint;
     4 import android.app.Activity;
     5 import android.os.Bundle;
     6 import android.view.Menu;
     7 import android.widget.ImageView;
     8 import android.widget.RatingBar;
     9 import android.widget.RatingBar.OnRatingBarChangeListener;
    10 
    11 public class MainActivity extends Activity {
    12     private ImageView imageView;
    13     private RatingBar ratingBar;
    14     @Override
    15     protected void onCreate(Bundle savedInstanceState) {
    16         super.onCreate(savedInstanceState);
    17         setContentView(R.layout.main);
    18         //获得控件对象
    19         imageView = (ImageView)findViewById(R.id.imageView);
    20         ratingBar = (RatingBar)findViewById(R.id.ratingBar);
    21         //为RatingBar绑定监听器
    22         ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
    23             
    24             @SuppressLint("NewApi")
    25             @Override
    26             public void onRatingChanged(RatingBar arg0, float arg1, boolean arg2) {
    27                 // TODO Auto-generated method stub
    28                 //动态改变图片透明度
    29                 int ratingInt = (int)(255 / 5 * arg1);
    30                 imageView.setImageAlpha(ratingInt);
    31             }
    32         });
    33     }
    34 
    35     @Override
    36     public boolean onCreateOptionsMenu(Menu menu) {
    37         // Inflate the menu; this adds items to the action bar if it is present.
    38         getMenuInflater().inflate(R.menu.main, menu);
    39         return true;
    40     }
    41 
    42 }

    2.xml文件

     1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     2     android:layout_width="fill_parent"
     3     android:layout_height="fill_parent"
     4     android:orientation="vertical" >
     5     <ImageView
     6         android:id="@+id/imageView"
     7         android:layout_width="wrap_content"
     8         android:layout_height="wrap_content"
     9         android:src="@drawable/home"
    10         android:layout_gravity="center_horizontal"
    11         />
    12 
    13     <RatingBar
    14         android:id="@+id/ratingBar"
    15         android:layout_width="wrap_content"
    16         android:layout_height="wrap_content"
    17         android:numStars="5"
    18         android:max="255"
    19         android:progress="255"
    20         android:stepSize="0.5"        
    21         />
    22 </LinearLayout>
  • 相关阅读:
    第三方驱动备份与还原
    Greenplum 解决 gpstop -u 指令报错
    yum安装(卸载)本地rpm包的方法(卸载本地安装的greenplum 5.19.rpm)
    Java JUC(java.util.concurrent工具包)
    netty 详解(八)基于 Netty 模拟实现 RPC
    netty 详解(七)netty 自定义协议解决 TCP 粘包和拆包
    netty 详解(六)netty 自定义编码解码器
    netty 详解(五)netty 使用 protobuf 序列化
    netty 详解(四)netty 开发 WebSocket 长连接程序
    netty 详解(三)netty 心跳检测机制案例
  • 原文地址:https://www.cnblogs.com/gdpdroid/p/3738877.html
Copyright © 2011-2022 走看看