标签:ratingbar 用户界面 android 实例 开发
Focus on technology, enjoy life!—— QQ:804212028
浏览链接:http://blog.csdn.net/y18334702058/article/details/44624305
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