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

Android---32---RatingBar

时间:2015-04-26 16:44:32      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:android   ratingbar   


技术分享


MainActivity.java:


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

public class MainActivity extends Activity implements OnRatingBarChangeListener {

	private RatingBar ratingBar;

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

		ratingBar = (RatingBar) findViewById(R.id.ratingbar);

		ratingBar.setMax(100);// 设置最大刻度
		ratingBar.setProgress(20);// 设置当前刻度
		ratingBar.setOnRatingBarChangeListener(this);
	}

	@Override
	public void onRatingChanged(RatingBar ratingBar, float rating,
			boolean fromUser) {
		// TODO Auto-generated method stub
		int progress = ratingBar.getProgress();
		Toast.makeText(MainActivity.this,
				"progress:" + progress + "    rating:" + rating + "是否是用户触发:" + fromUser, 0).show();

	}

}


activity_main.xml:


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.ratingbardemo.MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="评分控件的使用"
        android:textSize="20dp" />

    <RatingBar
        android:id="@+id/ratingbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>


Android---32---RatingBar

标签:android   ratingbar   

原文地址:http://blog.csdn.net/u013476556/article/details/45289305

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