├── .classpath
├── .gitignore
├── .project
├── .settings
├── org.eclipse.core.resources.prefs
├── org.eclipse.core.runtime.prefs
└── org.eclipse.jdt.core.prefs
├── AndroidManifest.xml
├── README.md
├── gif
└── LStarRatingBar.gif
├── ic_launcher-web.png
├── libs
└── android-support-v4.jar
├── proguard-project.txt
├── project.properties
├── res
├── drawable-hdpi
│ ├── ic_launcher.png
│ ├── no_star.png
│ ├── star_bottom.png
│ └── star_top.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── layout
│ └── activity_main.xml
├── menu
│ └── main.xml
├── values-v11
│ └── styles.xml
├── values-v14
│ └── styles.xml
├── values-w820dp
│ └── dimens.xml
└── values
│ ├── attrs.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
└── src
└── com
└── gc
└── starratingbar
├── MainActivity.java
├── constants
└── StarContants.java
├── effect
├── AlphaAnimation.java
├── ScaleAnimation.java
└── TranslationAnimation.java
└── views
└── LStarRatingBar.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /bin
2 | /gen
3 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | StarRatingBar
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/com/gc/starratingbar/views/LStarRatingBar.java=UTF-8
3 | encoding/=UTF-8
4 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.core.runtime.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | line.separator=\r\n
3 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3 | org.eclipse.jdt.core.compiler.compliance=1.6
4 | org.eclipse.jdt.core.compiler.source=1.6
5 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
17 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # StarRatingBar
2 | The Simple Custom RatingBar that has a series of animations
3 | 一个自定义的用展示评分的控件。目前有平移动画效果,透明度动画效果,放大缩小动画效果。
4 | 具体使用,还是请看代码,很简单
5 | 
6 |
--------------------------------------------------------------------------------
/gif/LStarRatingBar.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gcgongchao/StarRatingBar/ebd26ea0aaffa1904dd59667055434ad41f4463b/gif/LStarRatingBar.gif
--------------------------------------------------------------------------------
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gcgongchao/StarRatingBar/ebd26ea0aaffa1904dd59667055434ad41f4463b/ic_launcher-web.png
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gcgongchao/StarRatingBar/ebd26ea0aaffa1904dd59667055434ad41f4463b/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-19
15 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gcgongchao/StarRatingBar/ebd26ea0aaffa1904dd59667055434ad41f4463b/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/no_star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gcgongchao/StarRatingBar/ebd26ea0aaffa1904dd59667055434ad41f4463b/res/drawable-hdpi/no_star.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/star_bottom.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gcgongchao/StarRatingBar/ebd26ea0aaffa1904dd59667055434ad41f4463b/res/drawable-hdpi/star_bottom.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/star_top.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gcgongchao/StarRatingBar/ebd26ea0aaffa1904dd59667055434ad41f4463b/res/drawable-hdpi/star_top.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gcgongchao/StarRatingBar/ebd26ea0aaffa1904dd59667055434ad41f4463b/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gcgongchao/StarRatingBar/ebd26ea0aaffa1904dd59667055434ad41f4463b/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gcgongchao/StarRatingBar/ebd26ea0aaffa1904dd59667055434ad41f4463b/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
9 |
22 |
35 |
49 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
13 |
--------------------------------------------------------------------------------
/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 | 64dp
9 |
10 |
11 |
--------------------------------------------------------------------------------
/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | StarRatingBar
5 | Hello world!
6 | Settings
7 |
8 |
9 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/com/gc/starratingbar/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.gc.starratingbar;
2 |
3 |
4 |
5 | import android.app.Activity;
6 | import android.os.Bundle;
7 | /**
8 | *
9 | * @author GeneralAndroid
10 | * @time 2015/08/05
11 | */
12 |
13 | public class MainActivity extends Activity {
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_main);
19 |
20 |
21 | }
22 |
23 |
24 |
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/com/gc/starratingbar/constants/StarContants.java:
--------------------------------------------------------------------------------
1 | package com.gc.starratingbar.constants;
2 |
3 | public class StarContants {
4 |
5 | public static final int defEffect=0;
6 | public static final int scaleEffect=1;
7 | public static final int alphaEffect=2;
8 | public static final int translationEffect=3;
9 | }
10 |
--------------------------------------------------------------------------------
/src/com/gc/starratingbar/effect/AlphaAnimation.java:
--------------------------------------------------------------------------------
1 | package com.gc.starratingbar.effect;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorSet;
5 | import android.animation.ObjectAnimator;
6 | import android.animation.Animator.AnimatorListener;
7 | import android.os.Handler;
8 | import android.view.View;
9 |
10 | import com.gc.starratingbar.R;
11 |
12 | public class AlphaAnimation {
13 | public static void startAnimation(final View object,int duration,final int index,final Handler mHandler,final int starNum)
14 | {
15 | AnimatorSet set = new AnimatorSet();
16 | set.playTogether(
17 | ObjectAnimator.ofFloat(object, "alpha", 0, 1f),
18 | ObjectAnimator.ofFloat(object, "alpha", 1f, 0),
19 | ObjectAnimator.ofFloat(object, "alpha", 0, 1f)
20 | // ObjectAnimator.ofFloat(object, "scaleX", 2f, 1f),
21 | // ObjectAnimator.ofFloat(object, "scaleY", 2f, 1f)
22 |
23 | );
24 | set.addListener(new AnimatorListener() {
25 | @Override
26 | public void onAnimationStart(Animator animation) {
27 | object.setBackgroundResource(R.drawable.star_bottom);
28 | }
29 | @Override
30 | public void onAnimationRepeat(Animator animation) {
31 |
32 | }
33 | @Override
34 | public void onAnimationEnd(Animator animation) {
35 |
36 | object.setBackgroundResource(R.drawable.star_top);
37 | if(index>(starNum-2))
38 | {
39 | //
40 | }else {
41 | mHandler.sendEmptyMessage(index+1);
42 | }
43 | //
44 | }
45 |
46 | @Override
47 | public void onAnimationCancel(Animator animation) {
48 | }
49 | });
50 |
51 | set.setDuration(duration).start();
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/com/gc/starratingbar/effect/ScaleAnimation.java:
--------------------------------------------------------------------------------
1 | package com.gc.starratingbar.effect;
2 |
3 |
4 |
5 | import com.gc.starratingbar.R;
6 |
7 | import android.animation.Animator;
8 | import android.animation.AnimatorSet;
9 | import android.animation.ObjectAnimator;
10 | import android.animation.Animator.AnimatorListener;
11 | import android.os.Handler;
12 | import android.os.Message;
13 | import android.view.View;
14 | /**
15 | *
16 | * @author GeneralAndroid
17 | * @function �ȷŴ�����С
18 | */
19 | public class ScaleAnimation {
20 |
21 |
22 | public static void startAnimation(final View object,int duration,final int index,final Handler mHandler,final int starNum)
23 | {
24 | AnimatorSet set = new AnimatorSet();
25 | set.playTogether(
26 | ObjectAnimator.ofFloat(object, "scaleX", 1, 2f),
27 | ObjectAnimator.ofFloat(object, "scaleY", 1, 2f),
28 | ObjectAnimator.ofFloat(object, "scaleX", 2f, 1f),
29 | ObjectAnimator.ofFloat(object, "scaleY", 2f, 1f)
30 |
31 | );
32 | set.addListener(new AnimatorListener() {
33 | @Override
34 | public void onAnimationStart(Animator animation) {
35 | object.setBackgroundResource(R.drawable.star_bottom);
36 | }
37 | @Override
38 | public void onAnimationRepeat(Animator animation) {
39 |
40 | }
41 | @Override
42 | public void onAnimationEnd(Animator animation) {
43 |
44 | object.setBackgroundResource(R.drawable.star_top);
45 | if(index>(starNum-2))
46 | {
47 | //
48 | }else {
49 | mHandler.sendEmptyMessage(index+1);
50 | }
51 | //
52 | }
53 |
54 | @Override
55 | public void onAnimationCancel(Animator animation) {
56 | }
57 | });
58 |
59 | set.setDuration(duration).start();
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/com/gc/starratingbar/effect/TranslationAnimation.java:
--------------------------------------------------------------------------------
1 | package com.gc.starratingbar.effect;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorSet;
5 | import android.animation.ObjectAnimator;
6 | import android.animation.Animator.AnimatorListener;
7 | import android.os.Handler;
8 | import android.view.View;
9 |
10 | import com.gc.starratingbar.R;
11 |
12 | public class TranslationAnimation {
13 | public static void startAnimation(final View object,int duration,final int index,final Handler mHandler,final int starNum)
14 | {
15 | AnimatorSet set = new AnimatorSet();
16 | set.playTogether(
17 | ObjectAnimator.ofFloat(object, "translationX", -100, object.getTranslationX())
18 | // ObjectAnimator.ofFloat(object, "translationX", object.getWidth()/2,object.getWidth())
19 |
20 |
21 | );
22 | set.addListener(new AnimatorListener() {
23 | @Override
24 | public void onAnimationStart(Animator animation) {
25 | object.setBackgroundResource(R.drawable.star_bottom);
26 | }
27 | @Override
28 | public void onAnimationRepeat(Animator animation) {
29 |
30 | }
31 | @Override
32 | public void onAnimationEnd(Animator animation) {
33 |
34 | object.setBackgroundResource(R.drawable.star_top);
35 | if(index>(starNum-2))
36 | {
37 | //
38 | }else {
39 | mHandler.sendEmptyMessage(index+1);
40 | }
41 | //
42 | }
43 |
44 | @Override
45 | public void onAnimationCancel(Animator animation) {
46 | }
47 | });
48 |
49 | set.setDuration(duration).start();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/com/gc/starratingbar/views/LStarRatingBar.java:
--------------------------------------------------------------------------------
1 | package com.gc.starratingbar.views;
2 |
3 | import com.gc.starratingbar.R;
4 | import com.gc.starratingbar.constants.StarContants;
5 | import com.gc.starratingbar.effect.AlphaAnimation;
6 | import com.gc.starratingbar.effect.ScaleAnimation;
7 | import com.gc.starratingbar.effect.TranslationAnimation;
8 |
9 | import android.R.integer;
10 | import android.annotation.SuppressLint;
11 | import android.content.Context;
12 | import android.content.res.TypedArray;
13 | import android.graphics.drawable.Drawable;
14 | import android.os.Handler;
15 | import android.os.Message;
16 | import android.util.AttributeSet;
17 | import android.widget.ImageView;
18 | import android.widget.LinearLayout;
19 | /**
20 | *
21 | * @author GeneralAndroid
22 | * @function The Custom RatingBar has a series of animations;
23 | * @time 2015/07/27
24 | */
25 | @SuppressLint({ "Recycle", "NewApi" })
26 | public class LStarRatingBar extends LinearLayout{
27 |
28 | private Context mContext;
29 |
30 | /**
31 | * ����ֵ�IJ�ͬӦ�ò�ͬ�Ķ���Ч��
32 | */
33 | private int animationEffect;
34 | /**
35 | * ����δѡ�е�ͼƬ��Դ
36 | */
37 | private Drawable starUnselect;
38 | /**
39 | * ����ѡ�е�ͼƬ��Դ
40 | */
41 | private Drawable starSelected;
42 | /**
43 | * ����ѡ�е���������
44 | */
45 | private int starSelectedNum;
46 | private ImageView mIvStarOne,mIvStarSecond,mIvStarThree,mIvStarFour,mIvStarFive;
47 | private Handler mHandler=new Handler()
48 | {
49 |
50 | @Override
51 | public void handleMessage(Message msg) {
52 | // TODO Auto-generated method stub
53 | super.handleMessage(msg);
54 | startAnimation(msg.what);
55 | }
56 |
57 | };
58 | public LStarRatingBar(Context context) {
59 | this(context, null);
60 |
61 | }
62 |
63 | public LStarRatingBar(Context context, AttributeSet attrs) {
64 | super(context, attrs);
65 | this.mContext=context;
66 | TypedArray mTypedArray=context.obtainStyledAttributes(attrs, R.styleable.LStarRatingBar);
67 | //��ȡ�Զ������Ե�ֵ
68 | // orientation=mTypedArray.getInt(R.styleable.LStarRatingBar_orientation, 0);
69 | animationEffect=mTypedArray.getInt(R.styleable.LStarRatingBar_animationEffect, 0);
70 | starUnselect=mTypedArray.getDrawable(R.styleable.LStarRatingBar_starUnselect);
71 | starSelected=mTypedArray.getDrawable(R.styleable.LStarRatingBar_starSelected);
72 | starSelectedNum=mTypedArray.getInt(R.styleable.LStarRatingBar_starSelectedNum, 0);
73 | initView();
74 | startAnimation(0);
75 | }
76 | private void initView()
77 | {
78 | removeAllViews();
79 | mIvStarOne=new ImageView(mContext);
80 | mIvStarOne.setBackground(starUnselect);
81 | mIvStarSecond=new ImageView(mContext);
82 | mIvStarSecond.setBackground(starUnselect);
83 | mIvStarThree=new ImageView(mContext);
84 | mIvStarThree.setBackground(starUnselect);
85 | mIvStarFour=new ImageView(mContext);
86 | mIvStarFour.setBackground(starUnselect);
87 | mIvStarFive=new ImageView(mContext);
88 | mIvStarFive.setBackground(starUnselect);
89 | LayoutParams mLayoutParams=new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
90 | mLayoutParams.setMargins(10, 10,10, 10);
91 | if(animationEffect==StarContants.scaleEffect)
92 | {
93 | mLayoutParams.bottomMargin=30;
94 | mLayoutParams.topMargin=30;
95 | }
96 |
97 | this.addView(mIvStarOne, mLayoutParams);
98 | this.addView(mIvStarSecond, mLayoutParams);
99 | this.addView(mIvStarThree, mLayoutParams);
100 | this.addView(mIvStarFour, mLayoutParams);
101 | this.addView(mIvStarFive, mLayoutParams);
102 |
103 | }
104 | private void startAnimation(int index)
105 | {
106 | switch (animationEffect) {
107 | case StarContants.defEffect:
108 |
109 | break;
110 | case StarContants.scaleEffect:
111 | // this.setPadding(20, 20, 20, );
112 | // LayoutParams mLayoutParams=(LayoutParams) this.getLayoutParams();
113 | // mLayoutParams.bottomMargin=20;
114 | // mLayoutParams.topMargin=20;
115 | // setLayoutParams(mLayoutParams);
116 |
117 | switch (index) {
118 | case 0:
119 | ScaleAnimation.startAnimation(mIvStarOne, 360, 0,mHandler,starSelectedNum);
120 | break;
121 | case 1:
122 | ScaleAnimation.startAnimation(mIvStarSecond, 360, 1,mHandler,starSelectedNum);
123 | break;
124 | case 2:
125 | ScaleAnimation.startAnimation(mIvStarThree, 360, 2,mHandler,starSelectedNum);
126 | break;
127 | case 3:
128 | ScaleAnimation.startAnimation(mIvStarFour, 360, 3,mHandler,starSelectedNum);
129 | break;
130 | case 4:
131 | ScaleAnimation.startAnimation(mIvStarFive, 360, 4,mHandler,starSelectedNum);
132 | break;
133 |
134 |
135 | default:
136 | break;
137 | }
138 | break;
139 | case StarContants.alphaEffect:
140 | switch (index) {
141 | case 0:
142 | AlphaAnimation.startAnimation(mIvStarOne, 720, 0,mHandler,starSelectedNum);
143 | break;
144 | case 1:
145 | AlphaAnimation.startAnimation(mIvStarSecond, 720, 1,mHandler,starSelectedNum);
146 | break;
147 | case 2:
148 | AlphaAnimation.startAnimation(mIvStarThree, 720, 2,mHandler,starSelectedNum);
149 | break;
150 | case 3:
151 | AlphaAnimation.startAnimation(mIvStarFour, 720, 3,mHandler,starSelectedNum);
152 | break;
153 | case 4:
154 | AlphaAnimation.startAnimation(mIvStarFive, 720, 4,mHandler,starSelectedNum);
155 | break;
156 |
157 |
158 | default:
159 | break;
160 | }
161 | break;
162 | case StarContants.translationEffect:
163 | switch (index) {
164 | case 0:
165 | TranslationAnimation.startAnimation(mIvStarOne, 720, 0,mHandler,starSelectedNum);
166 | break;
167 | case 1:
168 | TranslationAnimation.startAnimation(mIvStarSecond, 720, 1,mHandler,starSelectedNum);
169 | break;
170 | case 2:
171 | TranslationAnimation.startAnimation(mIvStarThree, 720, 2,mHandler,starSelectedNum);
172 | break;
173 | case 3:
174 | TranslationAnimation.startAnimation(mIvStarFour, 720, 3,mHandler,starSelectedNum);
175 | break;
176 | case 4:
177 | TranslationAnimation.startAnimation(mIvStarFive, 720, 4,mHandler,starSelectedNum);
178 | break;
179 |
180 |
181 | default:
182 | break;
183 | }
184 | break;
185 | default:
186 | break;
187 | }
188 | }
189 |
190 |
191 | }
192 |
--------------------------------------------------------------------------------