关闭

android RatingBar 自定义

290人阅读 评论(0) 收藏 举报
分类:
<pre name="code" class="html">


如图:红框所示效果: 小人开了个淘宝店欢迎大婶们来往关注:左手阡陌

package com.qiao.ratingbartest;


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 {
	
	private RatingBar ratingBar_android;
	private RatingBar ratingBar_self;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initListener();
        
    }
	private void initListener() {
		ratingBar_android.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
			
			@Override
			public void onRatingChanged(RatingBar arg0, float arg1, boolean arg2) {
				Toast.makeText(MainActivity.this, "评分:= "+arg1, Toast.LENGTH_SHORT).show();
			}
		});
        ratingBar_self.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
        	
        	@Override
        	public void onRatingChanged(RatingBar arg0, float arg1, boolean arg2) {
        		Toast.makeText(MainActivity.this, "评分:= "+arg1, Toast.LENGTH_SHORT).show();
        	}
        });
	}
	private void initView() {
		ratingBar_android = (RatingBar) findViewById(R.id.ratingBar_android);
        ratingBar_self = (RatingBar) findViewById(R.id.ratingBar_self);
	}


}


<style name="myCustomizeRatingBar" parent="@android:style/Widget.RatingBar">
    	    <item name="android:progressDrawable">@drawable/star_conf_file</item>
    	    <item name="android:minHeight">16dip</item>
    	    <item name="android:maxHeight">16dip</item>
    	</style>


<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"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <RatingBar
        android:id="@+id/ratingBar_self"
        style="@style/myCustomizeRatingBar"
        android:layout_width="wrap_content"
        android:layout_height="18.5dp"
        android:layout_marginLeft="20dp"
        android:isIndicator="false"
        android:numStars="5"
        android:stepSize="1" />

</LinearLayout>






0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:36959次
    • 积分:1302
    • 等级:
    • 排名:千里之外
    • 原创:94篇
    • 转载:16篇
    • 译文:0篇
    • 评论:4条
    最新评论