public class RatingBar extends LinearLayout {
public RatingBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
}
/** * max为 0 */ public void setRating(int count){
//获得子控件的总个数 int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
ImageView iv = (ImageView) getChildAt(i);
if(i<count) {
iv.setImageResource(R.drawable.start_selected);
}else {
iv.setImageResource(R.drawable.start_normal);
}
}
}
}
//注意布局倒包不要倒错 R.drawable.start_selected图片自己找