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

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

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。