Skip to content

Commit 841620c

Browse files
author
chenyw
committed
commit
1 parent be41ceb commit 841620c

File tree

7 files changed

+50
-17
lines changed

7 files changed

+50
-17
lines changed

.idea/caches/build_file_checksums.ser

499 Bytes
Binary file not shown.

.idea/codeStyles/Project.xml

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 25
4+
compileSdkVersion 24
55
buildToolsVersion "25.0.3"
66
defaultConfig {
77
applicationId "com.hencoder.hencoderpracticedraw2"
@@ -20,7 +20,7 @@ android {
2020
}
2121

2222
dependencies {
23-
compile fileTree(dir: 'libs', include: ['*.jar'])
23+
compile fileTree(include: ['*.jar'], dir: 'libs')
2424
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
2525
exclude group: 'com.android.support', module: 'support-annotations'
2626
})

app/src/main/java/com/hencoder/hencoderpracticedraw2/practice/Practice01LinearGradientView.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
import android.content.Context;
44
import android.graphics.Canvas;
55
import android.graphics.Color;
6+
import android.graphics.LinearGradient;
67
import android.graphics.Paint;
8+
import android.graphics.Shader;
79
import android.support.annotation.Nullable;
810
import android.util.AttributeSet;
911
import android.view.View;
1012

1113
public class Practice01LinearGradientView extends View {
1214
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
15+
Shader shader = new LinearGradient(100,100,500,500,Color.parseColor("#E91E63"),Color.parseColor("#2196F3"),Shader.TileMode.CLAMP);
1316

1417
public Practice01LinearGradientView(Context context) {
1518
super(context);
@@ -24,14 +27,21 @@ public Practice01LinearGradientView(Context context, @Nullable AttributeSet attr
2427
}
2528

2629
{
30+
/**
31+
* LinearGradient(float x0, float y0, float x1, float y1, int color0, int color1, Shader.TileMode tile) 。
32+
33+
参数:
34+
x0 y0 x1 y1:渐变的两个端点的位置
35+
color0 color1 是端点的颜色
36+
*/
2737
// 用 Paint.setShader(shader) 设置一个 LinearGradient
2838
// LinearGradient 的参数:坐标:(100, 100) 到 (500, 500) ;颜色:#E91E63 到 #2196F3
2939
}
3040

3141
@Override
3242
protected void onDraw(Canvas canvas) {
3343
super.onDraw(canvas);
34-
44+
paint.setShader(shader);
3545
canvas.drawCircle(300, 300, 200, paint);
3646
}
3747
}

0 commit comments

Comments
 (0)