zoukankan      html  css  js  c++  java
  • Android常用控件之RatingBar的使用

    RatingBar控件比较常见就是用来做评分控件,先上图看看什么是RatingBar


    在布局文件中声明

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
        
    
        <RatingBar 
            android:id="@+id/ratingbar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:numStars="5"
            android:stepSize="0.1"/>
    </LinearLayout>

    numStars表示有多少颗星, stepSize表示每次滑动的大小


    在Activity中的代码

    package com.example.ratingbar;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.RatingBar;
    
    import com.example.widgetdemo.R;
    
    public class ratingBarActivity extends Activity {
    	
    	private RatingBar ratingBar = null;
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		// TODO Auto-generated method stub
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.ratingbar);
    		ratingBar = (RatingBar)findViewById(R.id.ratingbar);
    		ratingBar.setOnRatingBarChangeListener(new ratingChangeListener());
    	}
    	 class ratingChangeListener implements RatingBar.OnRatingBarChangeListener{
    
    		@Override
    		public void onRatingChanged(RatingBar ratingBar, float rating,
    				boolean fromUser) {
    			// TODO Auto-generated method stub
    			if(fromUser){
    				System.out.println("onRatingChanged " + rating);
    			}
    		}
    		 
    	 }
    }
    


    这个控件比较简单,同样也可以参考源码

    点击打开链接

  • 相关阅读:
    SA练习题总结-篇一
    树上距离(树形DP)
    Codeforces Round #633(Div.2) E. Perfect Triples
    Codeforces Round #633 (Div. 2) D.Edge Weight Assignment
    问题 B: FZB(树形DP+边记忆化)
    【Matlab】自学笔记——基础知识篇
    【Python科学计算】Numpy——ndarry
    退役总结
    [树的遍历]树的遍历(PTA)
    [stl]集合相似度(PTA)
  • 原文地址:https://www.cnblogs.com/pangblog/p/3294104.html
Copyright © 2011-2022 走看看