写代码的四点:
1.明确需求。要做什么?
2.分析思路。要怎么做?(1,2,3……)
3.确定步骤。每一个思路要用到哪些语句、方法和对象。
4.代码实现。用具体的语言代码将思路实现出来。
学习新技术的四点:
1.该技术是什么?
2.该技术有什么特点?(使用需注意的方面)
3.该技术怎么使用?(写Demo)
4.该技术什么时候用?(在Project中的使用场景 )
----------------------早计划,早准备,早完成。-------------------------
代码如下:
package com.wy.test.other; import android.content.Context; import android.graphics.Canvas; import android.graphics.Path; import android.graphics.RectF; import android.util.AttributeSet; import android.widget.ImageView; /** * 圆角的imageview */ public class RoundCornerImageView extends ImageView { public RoundCornerImageView(Context context) { super(context); } public RoundCornerImageView(Context context, AttributeSet attrs) { super(context, attrs); } public RoundCornerImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onDraw(Canvas canvas) { Path clipPath = new Path(); int w = this.getWidth(); int h = this.getHeight(); clipPath.addRoundRect(new RectF(0, 0, w, h), 20.0f, 20.0f, Path.Direction.CW); canvas.clipPath(clipPath); super.onDraw(canvas); } }
在项目中的应用:
在xml布局文件中直接使用;
<com.wy.test.other.RoundCornerImageView android:src="#000000" android:layout_width="100dp" android:layout_height="100dp" />