码迷,mamicode.com
首页 > 移动开发 > 详细

步步为营_Android开发课[27]_用户界面之RatingBar(评分栏)

时间:2015-04-14 13:01:16      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:ratingbar   用户界面   android   实例   开发   

Focus on technology, enjoy life!—— QQ:804212028
浏览链接:http://blog.csdn.net/y18334702058/article/details/44624305


  • 主题:用户界面之RatingBar(评分栏)
    -这个很简单,平时用的也不多,一般用的上就是给电影或者书籍评分;

RatingBar评分栏(实例)
activity_main.xml:

<?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"
    android:id="@+id/mainlayout" >

     <RatingBar 
        android:id="@+id/ratingbar1"
        style="android:attr/ratingBarStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
</LinearLayout>

MainActivity.java:

import android.app.Activity;
import android.os.Bundle;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.Toast;

public class MainActivity extends Activity {

    RatingBar ratingbar1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ratingbar1 = (RatingBar)findViewById(R.id.ratingbar1);

        ratingbar1.setOnRatingBarChangeListener(new listener());

    }     

    class listener implements OnRatingBarChangeListener{

        @Override
        public void onRatingChanged(RatingBar RatingBar , float rating, boolean fromUser) {
            // TODO Auto-generated method stub
            switch(RatingBar.getId()){
            case R.id.ratingbar1:
                ratingbar1.setRating(rating);
                Toast.makeText(MainActivity.this,"rating:" + String.valueOf(rating),Toast.LENGTH_LONG).show();
                break;
            }
        }
    }
}

运行结果:

技术分享

Focus on technology, enjoy life!—— QQ:804212028
浏览链接:http://blog.csdn.net/y18334702058/article/details/44624305

步步为营_Android开发课[27]_用户界面之RatingBar(评分栏)

标签:ratingbar   用户界面   android   实例   开发   

原文地址:http://blog.csdn.net/y18334702058/article/details/45039581

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!