├── .gitattributes
├── .gitignore
├── .idea
├── caches
│ └── build_file_checksums.ser
├── codeStyles
│ └── Project.xml
├── gradle.xml
├── misc.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── example
│ │ └── administrator
│ │ └── animatecircleimageview
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── administrator
│ │ │ └── animatecircleimageview
│ │ │ ├── MainActivity.java
│ │ │ ├── utils
│ │ │ ├── ScreenUtil.java
│ │ │ └── ViewTrackController.java
│ │ │ └── views
│ │ │ ├── AnimateImageViewItem.java
│ │ │ └── DragImageView.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── head.png
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── attrs_circle_view.xml
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── example
│ └── administrator
│ └── animatecircleimageview
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/libraries
5 | /.idea/modules.xml
6 | /.idea/workspace.xml
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CeuiLiSA/AnimateCircleImageViewLibrary/8053df51af440809a0f399fd464e7fa9fefa35e4/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AnimateCircleImageViewLibrary
2 |
3 | 可以拖拽的CircleImageView
4 |
5 | 从屏幕松手图片位置自动复原,带回弹效果
6 |
7 | 
8 |
9 | # How to use
10 |
11 | Step 1. Add the JitPack repository to your build file
12 | ~~~
13 | allprojects {
14 | repositories {
15 | ...
16 | maven { url 'https://jitpack.io' }
17 | }
18 | }
19 | ~~~
20 |
21 | Step 2. Add the dependency
22 | ~~~
23 | dependencies {
24 | implementation 'com.github.CeuiLiSA:AnimateCircleImageViewLibrary:1.1.0'
25 | }
26 | ~~~
27 |
28 | Step 3. use it in xml
29 | ~~~
30 |
31 |
43 |
44 |
45 | ~~~
46 |
47 | Step 4. in xxx.class
48 |
49 | 加载本地图片:
50 | ~~~
51 | public class MainActivity extends AppCompatActivity {
52 | @Override
53 | protected void onCreate(Bundle savedInstanceState) {
54 | super.onCreate(savedInstanceState);
55 | setContentView(R.layout.activity_main);
56 |
57 | Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.head);
58 | DragImageView dragImageView = findViewById(R.id.my_image_view);
59 | dragImageView.setImageResource(bitmap);
60 | }
61 | }
62 | ~~~
63 |
64 | 加载网络图片:
65 |
66 | ~~~
67 | public class MainActivity extends AppCompatActivity {
68 |
69 | private DragImageView mDragImageView;
70 | private static final String url =
71 | "https://i.pximg.net/c/480x960/img-master/img/2018/03/18/00/00/03/67786060_p0_master1200.jpg";
72 |
73 | @Override
74 | protected void onCreate(Bundle savedInstanceState) {
75 | super.onCreate(savedInstanceState);
76 | setContentView(R.layout.activity_main);
77 |
78 | mDragImageView = findViewById(R.id.my_image_view);
79 | Glide.with(this).load(url).asBitmap().into(new SimpleTarget() {
80 | @Override
81 | public void onResourceReady(Bitmap resource, GlideAnimation super Bitmap> glideAnimation) {
82 | mDragImageView.setImageResource(resource);
83 | }
84 | });
85 | }
86 | }
87 | ~~~
88 |
89 | 使用到的开源库:
90 | ~~~
91 | implementation 'de.hdodenhof:circleimageview:2.2.0'
92 | implementation 'com.facebook.rebound:rebound:0.3.8'
93 | implementation 'com.github.bumptech.glide:glide:3.8.0'
94 | ~~~
95 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 27
5 | defaultConfig {
6 | minSdkVersion 21
7 | targetSdkVersion 27
8 | versionCode 1
9 | versionName "1.0"
10 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
11 | }
12 | buildTypes {
13 | release {
14 | minifyEnabled false
15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
16 | }
17 | }
18 | }
19 |
20 | dependencies {
21 | implementation fileTree(dir: 'libs', include: ['*.jar'])
22 | implementation 'com.android.support:appcompat-v7:26.1.0'
23 |
24 | implementation 'de.hdodenhof:circleimageview:2.2.0'
25 | implementation 'com.facebook.rebound:rebound:0.3.8'
26 | implementation 'com.github.bumptech.glide:glide:3.8.0'
27 |
28 | testImplementation 'junit:junit:4.12'
29 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
30 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
31 | }
32 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/administrator/animatecircleimageview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.administrator.animatecircleimageview;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.example.administrator.animatecircleimageview", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/administrator/animatecircleimageview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.administrator.animatecircleimageview;
2 |
3 | import android.graphics.Bitmap;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 |
7 | import com.bumptech.glide.Glide;
8 | import com.bumptech.glide.request.animation.GlideAnimation;
9 | import com.bumptech.glide.request.target.SimpleTarget;
10 | import com.example.administrator.animatecircleimageview.views.DragImageView;
11 | /**
12 | * Created by CeuiLiSA.
13 | */
14 | public class MainActivity extends AppCompatActivity {
15 |
16 | private DragImageView mDragImageView;
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_main);
22 |
23 | mDragImageView = findViewById(R.id.my_image_view);
24 | /*加载本地图片:
25 | Bitmap localBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.head);
26 | mDragImageView.setImageResource(localBitmap);
27 | */
28 | //加载网络图片
29 | String url = "https://i.pximg.net/c/480x960/img-master/img/2018/03/18/00/00/03/67786060_p0_master1200.jpg";
30 | Glide.with(this).load(url).asBitmap().into(new SimpleTarget() {
31 | @Override
32 | public void onResourceReady(Bitmap resource, GlideAnimation super Bitmap> glideAnimation) {
33 | mDragImageView.setImageResource(resource);
34 | }
35 | });
36 | }
37 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/administrator/animatecircleimageview/utils/ScreenUtil.java:
--------------------------------------------------------------------------------
1 | package com.example.administrator.animatecircleimageview.utils;
2 |
3 | import android.content.Context;
4 | import android.util.DisplayMetrics;
5 |
6 | /**
7 | * Created by CeuiLiSA.
8 | */
9 | public class ScreenUtil {
10 | /**
11 | * dip转px
12 | */
13 | public static int dip2px(Context context, float dipValue) {
14 | final float scale = context.getResources().getDisplayMetrics().density;
15 | return (int) (dipValue * scale + 0.5f);
16 | }
17 |
18 | /**
19 | * px转dip
20 | */
21 | public static int px2dip(Context context, float pxValue) {
22 | final float scale = context.getResources().getDisplayMetrics().density;
23 | return (int) (pxValue / scale + 0.5f);
24 | }
25 |
26 | /**
27 | * 获取屏幕高度
28 | * @param context
29 | * @return
30 | */
31 | public static int getScreenHeight(Context context){
32 | if (null == context) {
33 | return 0;
34 | }
35 | DisplayMetrics dm = context.getApplicationContext().getResources().getDisplayMetrics();
36 | return dm.heightPixels;
37 | }
38 |
39 | public static int getScreenWidth(Context context){
40 | if (null == context) {
41 | return 0;
42 | }
43 | DisplayMetrics dm = context.getApplicationContext().getResources().getDisplayMetrics();
44 | return dm.widthPixels;
45 | }
46 |
47 | /**
48 | * 将px值转换为sp值,保证文字大小不变
49 | * (DisplayMetrics类中属性scaledDensity)
50 | * @return
51 | */
52 | public static int px2sp(Context context, float pxValue) {
53 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
54 | return (int) (pxValue / fontScale + 0.5f);
55 | }
56 |
57 | /**
58 | * 将sp值转换为px值,保证文字大小不变
59 | * (DisplayMetrics类中属性scaledDensity)
60 | * @return
61 | */
62 | public static int sp2px(Context context, float spValue) {
63 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
64 | return (int) (spValue * fontScale + 0.5f);
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/administrator/animatecircleimageview/utils/ViewTrackController.java:
--------------------------------------------------------------------------------
1 | package com.example.administrator.animatecircleimageview.utils;
2 |
3 | import android.view.View;
4 |
5 | import com.example.administrator.animatecircleimageview.views.AnimateImageViewItem;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * Created by CeuiLiSA.
11 | */
12 | public class ViewTrackController {
13 | private List imageViewList;
14 | private AnimateImageViewItem topView;
15 | private AnimateImageViewItem topFollowerView;
16 | private int resetPosX, resetPosY;
17 |
18 | public ViewTrackController() {
19 | }
20 |
21 |
22 |
23 | public void init(List imageViewList) {
24 | this.imageViewList = imageViewList;
25 |
26 | int len = imageViewList.size();
27 | this.topView = imageViewList.get(len - 1);
28 | this.topFollowerView = imageViewList.get(len - 2);
29 |
30 | for (int i = 1; i < len; i++) {
31 | AnimateImageViewItem view1 = imageViewList.get(i - 1);
32 | AnimateImageViewItem view2 = imageViewList.get(i);
33 | view2.getSpringX().addListener(view1.getFollowerListenerX());
34 | view2.getSpringY().addListener(view1.getFollowerListenerY());
35 | }
36 | }
37 |
38 | /**
39 | * 拖动view的位置改变,后面的view会自动跟着变
40 | */
41 | public void onTopViewPosChanged(int xPos, int yPos) {
42 | // 第一个跟随者移动了,后面的跟随者会自动移动
43 | topFollowerView.animTo(xPos, yPos);
44 | }
45 |
46 | /**
47 | * 手指松开的时候调用
48 | */
49 | public void onRelease() {
50 | topView.onRelease(resetPosX, resetPosY);
51 | }
52 |
53 | /**
54 | * 设置view最初的原始位置
55 | */
56 | public void setOriginPos(int xPos, int yPos) {
57 | resetPosX = xPos;
58 | resetPosY = yPos;
59 |
60 | int len = imageViewList.size();
61 | for (int i = 0; i < len; i++) {
62 | imageViewList.get(i).setCurrentSpringPos(xPos, yPos);
63 | }
64 | }
65 |
66 | public void setOtherVisiable(boolean visiable) {
67 | int len = imageViewList.size();
68 | for (int i = 0; i < len; i++) {
69 | if (i != len - 1) {
70 | imageViewList.get(i).setVisibility(visiable ? View.VISIBLE : View.GONE);
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/administrator/animatecircleimageview/views/AnimateImageViewItem.java:
--------------------------------------------------------------------------------
1 | package com.example.administrator.animatecircleimageview.views;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 |
6 | import com.facebook.rebound.SimpleSpringListener;
7 | import com.facebook.rebound.Spring;
8 | import com.facebook.rebound.SpringSystem;
9 |
10 | import de.hdodenhof.circleimageview.CircleImageView;
11 |
12 | /**
13 | * Created by CeuiLiSA.
14 | */
15 | public class AnimateImageViewItem extends CircleImageView {
16 | private Spring springX, springY;
17 | private SimpleSpringListener followerListenerX, followerListenerY; // 此为跟踪的回调,当前面一个view移动的时候,此为后面的view,需要更新endValue
18 |
19 | public AnimateImageViewItem(Context context) {
20 | this(context, null);
21 | }
22 |
23 | public AnimateImageViewItem(Context context, AttributeSet attrs) {
24 | this(context, attrs, 0);
25 | }
26 |
27 | public AnimateImageViewItem(Context context, AttributeSet attrs, int defStyleAttr) {
28 | super(context, attrs, defStyleAttr);
29 |
30 | SpringSystem mSpringSystem = SpringSystem.create();
31 | springX = mSpringSystem.createSpring();
32 | springY = mSpringSystem.createSpring();
33 |
34 | springX.addListener(new SimpleSpringListener() {
35 | @Override
36 | public void onSpringUpdate(Spring spring) {
37 | int xPos = (int) spring.getCurrentValue();
38 | setScreenX(xPos);
39 | }
40 | });
41 |
42 | springY.addListener(new SimpleSpringListener() {
43 | @Override
44 | public void onSpringUpdate(Spring spring) {
45 | int yPos = (int) spring.getCurrentValue();
46 | setScreenY(yPos);
47 | }
48 | });
49 |
50 | followerListenerX = new SimpleSpringListener() {
51 | @Override
52 | public void onSpringUpdate(Spring spring) {
53 | int xPos = (int) spring.getCurrentValue();
54 | springX.setEndValue(xPos);
55 | }
56 | };
57 |
58 | followerListenerY = new SimpleSpringListener() {
59 | @Override
60 | public void onSpringUpdate(Spring spring) {
61 | int yPos = (int) spring.getCurrentValue();
62 | springY.setEndValue(yPos);
63 | }
64 | };
65 | }
66 |
67 | private void setScreenX(int screenX) {
68 | this.offsetLeftAndRight(screenX - getLeft());
69 | }
70 |
71 | private void setScreenY(int screenY) {
72 | this.offsetTopAndBottom(screenY - getTop());
73 | }
74 |
75 | public void animTo(int xPos, int yPos) {
76 | springX.setEndValue(xPos);
77 | springY.setEndValue(yPos);
78 | }
79 |
80 | /**
81 | * 顶部ImageView强行停止动画
82 | */
83 | public void stopAnimation() {
84 | springX.setAtRest();
85 | springY.setAtRest();
86 | }
87 |
88 | /**
89 | * 只为最顶部的view调用,触点松开后,回归原点
90 | */
91 | public void onRelease(int xPos, int yPos) {
92 | setCurrentSpringPos(getLeft(), getTop());
93 | animTo(xPos, yPos);
94 | }
95 |
96 | /**
97 | * 设置当前spring位置
98 | */
99 | public void setCurrentSpringPos(int xPos, int yPos) {
100 | springX.setCurrentValue(xPos);
101 | springY.setCurrentValue(yPos);
102 | }
103 |
104 | public Spring getSpringX() {
105 | return springX;
106 | }
107 |
108 | public Spring getSpringY() {
109 | return springY;
110 | }
111 |
112 | public SimpleSpringListener getFollowerListenerX() {
113 | return followerListenerX;
114 | }
115 |
116 | public SimpleSpringListener getFollowerListenerY() {
117 | return followerListenerY;
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/administrator/animatecircleimageview/views/DragImageView.java:
--------------------------------------------------------------------------------
1 | package com.example.administrator.animatecircleimageview.views;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Bitmap;
6 | import android.support.v4.view.ViewCompat;
7 | import android.support.v4.widget.ViewDragHelper;
8 | import android.util.AttributeSet;
9 | import android.util.Log;
10 | import android.view.MotionEvent;
11 | import android.view.View;
12 | import android.widget.RelativeLayout;
13 |
14 | import com.example.administrator.animatecircleimageview.R;
15 | import com.example.administrator.animatecircleimageview.utils.ScreenUtil;
16 | import com.example.administrator.animatecircleimageview.utils.ViewTrackController;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | /**
22 | * Created by CeuiLiSA.
23 | */
24 | public class DragImageView extends RelativeLayout {
25 |
26 | List mIvList;
27 | AnimateImageViewItem circleImageView;
28 | Context mContext;
29 | Bitmap imageResource;
30 | ViewDragHelper mDragHelper;
31 | ViewTrackController mViewTrackController;
32 | LayoutParams params;
33 | int circleImgRadius, topMargin, circleImgBorder, circleViewsCount, borderColor;
34 | public DragImageView(Context context) {
35 | super(context);
36 | }
37 |
38 | public DragImageView(Context context, AttributeSet attrs) {
39 | super(context, attrs);
40 | mContext = context;
41 | TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.DragImageView);
42 | circleImgRadius = a.getInteger(R.styleable.DragImageView_circleImgRadius, 110);
43 | topMargin = a.getInteger(R.styleable.DragImageView_topMargin, 45);
44 | circleImgBorder = a.getInteger(R.styleable.DragImageView_circleImgBorder, 3);
45 | circleViewsCount = a.getInteger(R.styleable.DragImageView_circleViewsCount, 5);
46 | borderColor = a.getColor(R.styleable.DragImageView_circleImgBorderColor, getResources().getColor(R.color.colorPrimary));
47 | a.recycle();
48 |
49 | mDragHelper = ViewDragHelper.create(this, 1.0f, new MyViewDragHelper());
50 | mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_TOP);
51 | mViewTrackController = new ViewTrackController();
52 | }
53 |
54 | public void setImageResource(Bitmap bitmap)
55 | {
56 | imageResource = bitmap;
57 | mIvList = new ArrayList<>();
58 | for (int i = 0; i < circleViewsCount; i++) {
59 | AnimateImageViewItem circleImageView = new AnimateImageViewItem(mContext);
60 | circleImageView.setImageBitmap(imageResource);
61 | circleImageView.setBorderWidth(ScreenUtil.dip2px(mContext, circleImgBorder));
62 | circleImageView.setBorderColor(borderColor);
63 | circleImageView.setLayoutParams(params);
64 | addView(circleImageView);
65 | if (i == circleViewsCount-1) {
66 | this.circleImageView = circleImageView;
67 | } else {
68 | circleImageView.setAlpha(0.3f);
69 | }
70 | mIvList.add(circleImageView);
71 | }
72 | mViewTrackController.init(mIvList);
73 | }
74 |
75 | @Override
76 | protected void onFinishInflate() {
77 | super.onFinishInflate();
78 | params = new LayoutParams(ScreenUtil.dip2px(mContext, circleImgRadius), ScreenUtil.dip2px(mContext, circleImgRadius));
79 | params.topMargin = ScreenUtil.dip2px(mContext, topMargin);
80 | params.leftMargin = ScreenUtil.getScreenWidth(mContext) / 2 - ScreenUtil.dip2px(mContext, circleImgRadius) / 2;
81 | }
82 |
83 | private class MyViewDragHelper extends ViewDragHelper.Callback {
84 | @Override
85 | public boolean tryCaptureView(View child, int pointerId) {
86 | if (child == circleImageView) {
87 | circleImageView.stopAnimation();
88 | return true;
89 | }
90 | return false;
91 | }
92 |
93 | @Override
94 | public int getViewVerticalDragRange(View child) {
95 | return 1;
96 | }
97 |
98 | @Override
99 | public int clampViewPositionHorizontal(View child, int left, int dx) {
100 | return left;
101 | }
102 |
103 | @Override
104 | public int clampViewPositionVertical(View child, int top, int dy) {
105 | return top;
106 | }
107 |
108 | @Override
109 | public void onViewReleased(View releasedChild, float xvel, float yvel) {
110 | mViewTrackController.onRelease();
111 | }
112 |
113 | @Override
114 | public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
115 | super.onViewPositionChanged(changedView, left, top, dx, dy);
116 | mViewTrackController.setOtherVisiable(true);
117 | mViewTrackController.onTopViewPosChanged(left, top);
118 | }
119 | }
120 |
121 | @Override
122 | public void computeScroll() {
123 | if (mDragHelper.continueSettling(true)) {
124 | ViewCompat.postInvalidateOnAnimation(this);
125 | }
126 | }
127 |
128 | @Override
129 | public boolean onInterceptTouchEvent(MotionEvent event) {
130 | if (event.getAction() == MotionEvent.ACTION_DOWN && clickInAvatarView(event)) {
131 | return true;
132 | }
133 | return mDragHelper.shouldInterceptTouchEvent(event);
134 | }
135 |
136 | @Override
137 | public boolean onTouchEvent(MotionEvent event) {
138 | mDragHelper.processTouchEvent(event);
139 | return true;
140 | }
141 |
142 | @Override
143 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
144 | super.onLayout(changed, l, t, r, b);
145 | mViewTrackController.setOriginPos(circleImageView.getLeft(), circleImageView.getTop());
146 | }
147 |
148 | /**
149 | * 判断点击位置是否位于头像圆形的里面
150 | */
151 | private boolean clickInAvatarView(MotionEvent event) {
152 | boolean isInCircle = true;
153 | int clickX = (int) event.getRawX();
154 | int clickY = (int) event.getRawY();
155 |
156 | //获取控件在屏幕的位置
157 | int[] location = new int[2];
158 | circleImageView.getLocationOnScreen(location);
159 |
160 | //控件相对于屏幕的x与y坐标
161 | int x = location[0];
162 | int y = location[1];
163 |
164 | //圆半径 通过左右坐标计算获得getLeft
165 | int r = (circleImageView.getRight() - circleImageView.getLeft()) / 2;
166 |
167 | //圆心坐标
168 | int vCenterX = x + r;
169 | int vCenterY = y + r;
170 |
171 | //点击位置x坐标与圆心的x坐标的距离
172 | int distanceX = Math.abs(vCenterX - clickX);
173 | //点击位置y坐标与圆心的y坐标的距离
174 | int distanceY = Math.abs(vCenterY - clickY);
175 | //点击位置与圆心的直线距离
176 | int distanceZ = (int) Math.sqrt(Math.pow(distanceX, 2) + Math.pow(distanceY, 2));
177 | if (distanceZ > r) {
178 | return false;
179 | }
180 | return isInCircle;
181 | }
182 |
183 | }
184 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/head.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CeuiLiSA/AnimateCircleImageViewLibrary/8053df51af440809a0f399fd464e7fa9fefa35e4/app/src/main/res/mipmap-hdpi/head.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CeuiLiSA/AnimateCircleImageViewLibrary/8053df51af440809a0f399fd464e7fa9fefa35e4/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CeuiLiSA/AnimateCircleImageViewLibrary/8053df51af440809a0f399fd464e7fa9fefa35e4/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CeuiLiSA/AnimateCircleImageViewLibrary/8053df51af440809a0f399fd464e7fa9fefa35e4/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CeuiLiSA/AnimateCircleImageViewLibrary/8053df51af440809a0f399fd464e7fa9fefa35e4/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CeuiLiSA/AnimateCircleImageViewLibrary/8053df51af440809a0f399fd464e7fa9fefa35e4/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CeuiLiSA/AnimateCircleImageViewLibrary/8053df51af440809a0f399fd464e7fa9fefa35e4/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CeuiLiSA/AnimateCircleImageViewLibrary/8053df51af440809a0f399fd464e7fa9fefa35e4/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CeuiLiSA/AnimateCircleImageViewLibrary/8053df51af440809a0f399fd464e7fa9fefa35e4/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CeuiLiSA/AnimateCircleImageViewLibrary/8053df51af440809a0f399fd464e7fa9fefa35e4/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CeuiLiSA/AnimateCircleImageViewLibrary/8053df51af440809a0f399fd464e7fa9fefa35e4/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/attrs_circle_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AnimateCircleImageView
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/example/administrator/animatecircleimageview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.administrator.animatecircleimageview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.1'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CeuiLiSA/AnimateCircleImageViewLibrary/8053df51af440809a0f399fd464e7fa9fefa35e4/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Apr 14 21:44:15 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------