Skip to content

Commit 0144adb

Browse files
committed
Updates
1 parent 8625da9 commit 0144adb

7 files changed

Lines changed: 75 additions & 6 deletions

File tree

READEME_CN.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717

1818
## 使用方法
1919

20+
#### Gradle 配置
21+
```
22+
dependencies {
23+
compile 'com.yinglan.shadowimageview:shadowimageview:1.0.2'
24+
}
25+
```
26+
2027
### 布局
2128

2229
```
@@ -35,6 +42,11 @@
3542
shadow.setImageDrawable(drawable);
3643
```
3744

45+
### 设置图片半径
46+
```
47+
shadow.setImageRadius(radius);
48+
```
49+
3850
## 注意
3951

4052
看了[PPMusicImageShadow](https://github.com/PierrePerrin/PPMusicImageShadow)的效果,抽时间做了简单实现没有上传Jcenter库,可能会有潜在的问题做学习交流使用,期待大家有更好的实现方式。

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717

1818
## Usage
1919

20+
#### Gradle
21+
```
22+
dependencies {
23+
compile 'com.yinglan.shadowimageview:shadowimageview:1.0.2'
24+
}
25+
```
26+
2027
### In layout
2128

2229
```
@@ -35,6 +42,11 @@
3542
shadow.setImageDrawable(drawable);
3643
```
3744

45+
### Set the picture radius
46+
```
47+
shadow.setImageRadius(radius);
48+
```
49+
3850
## FAQ
3951

4052
See [PPMusicImageShadow](https://github.com/PierrePerrin/PPMusicImageShadow), the effect of time has made the simple implementation no upload Jcenter library, there may be a potential problem for study and communication, looking forward to you have a better way of implementation.

app/src/main/java/com/yinglan/shadowdemo/MainActivity.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,26 @@
44
import android.graphics.drawable.BitmapDrawable;
55
import android.os.Bundle;
66
import android.support.v7.app.AppCompatActivity;
7+
import android.support.v7.widget.AppCompatSeekBar;
78
import android.view.View;
9+
import android.widget.SeekBar;
810

911
import com.yinglan.shadowimageview.ShadowImageView;
1012

1113
public class MainActivity extends AppCompatActivity {
1214

1315
private com.yinglan.shadowimageview.ShadowImageView shadow;
16+
private AppCompatSeekBar seekBar;
1417
private int resId = 1;
1518

19+
1620
@Override
1721
protected void onCreate(Bundle savedInstanceState) {
1822
super.onCreate(savedInstanceState);
1923
setContentView(R.layout.activity_main);
2024

2125
this.shadow = (ShadowImageView) findViewById(R.id.shadow);
26+
this.seekBar = (AppCompatSeekBar) findViewById(R.id.seekbar);
2227

2328
shadow.setOnClickListener(new View.OnClickListener() {
2429
@Override
@@ -48,5 +53,22 @@ public void onClick(View v) {
4853
shadow.setImageDrawable(getResources().getDrawable(res));
4954
}
5055
});
56+
57+
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
58+
@Override
59+
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
60+
shadow.setImageRadius(progress);
61+
}
62+
63+
@Override
64+
public void onStartTrackingTouch(SeekBar seekBar) {
65+
66+
}
67+
68+
@Override
69+
public void onStopTrackingTouch(SeekBar seekBar) {
70+
71+
}
72+
});
5173
}
5274
}
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
4-
xmlns:tools="http://schemas.android.com/tools"
54
android:layout_width="match_parent"
65
android:layout_height="match_parent"
76
android:background="@android:color/white"
8-
tools:context="com.yinglan.shadowdemo.MainActivity">
7+
android:orientation="vertical">
98

109
<com.yinglan.shadowimageview.ShadowImageView
1110
android:id="@+id/shadow"
1211
android:layout_width="300dp"
1312
android:layout_height="300dp"
14-
app:shadowRound="20dp"
13+
app:shadowRound="0dp"
1514
app:shadowSrc="@mipmap/lotus" />
1615

17-
</android.support.constraint.ConstraintLayout>
16+
<android.support.v7.widget.AppCompatSeekBar
17+
android:id="@+id/seekbar"
18+
android:layout_width="match_parent"
19+
android:layout_height="wrap_content"
20+
android:max="500" />
21+
22+
</LinearLayout>

shadowimageview/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ dependencies {
2929
compile 'com.android.support:appcompat-v7:25.1.1'
3030
compile 'com.android.support:palette-v7:25.0.0'
3131
testCompile 'junit:junit:4.12'
32-
}
32+
}

shadowimageview/src/main/java/com/yinglan/shadowimageview/ShadowImageView.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,36 @@ public void onGlobalLayout() {
8585

8686
public void setImageResource(int resId) {
8787
((RoundImageView) getChildAt(0)).setImageResource(resId);
88+
invalidate();
8889
mInvalidat = true;
8990
}
9091

9192
public void setImageDrawable(Drawable drawable) {
9293
((RoundImageView) getChildAt(0)).setImageDrawable(drawable);
94+
invalidate();
95+
mInvalidat = true;
96+
}
97+
98+
public void setImageRadius(int radius) {
99+
if (radius > getChildAt(0).getWidth() / 2 || radius > getChildAt(0).getHeight() / 2) {
100+
if (getChildAt(0).getWidth() > getChildAt(0).getHeight()) {
101+
radius = getChildAt(0).getHeight() / 2;
102+
} else {
103+
radius = getChildAt(0).getWidth() / 2;
104+
}
105+
}
106+
107+
this.shadowRound = radius;
108+
((RoundImageView) getChildAt(0)).setRound(shadowRound);
109+
invalidate();
93110
mInvalidat = true;
94111
}
95112

96113
@Override
97114
protected void dispatchDraw(Canvas canvas) {
98115

99116
if (mInvalidat) {
117+
100118
mInvalidat = false;
101119

102120
View view = getChildAt(0);

show/shadow.gif

1.03 MB
Loading

0 commit comments

Comments
 (0)