Created
April 3, 2015 06:48
-
-
Save happycodinggirl/44da24bde3f4bfe0b93c to your computer and use it in GitHub Desktop.
用画笔画了一个简单的箭头
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.huangxingli.testpath; | |
import android.content.Context; | |
import android.graphics.Canvas; | |
import android.graphics.Paint; | |
import android.graphics.Path; | |
import android.util.AttributeSet; | |
import android.view.View; | |
/** | |
* Created by huangxingli on 2015/4/3. | |
*/ | |
public class MyView extends View { | |
private Paint mPaint; | |
public MyView(Context context) { | |
super(context); | |
mPaint = new Paint(); | |
} | |
public MyView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
mPaint=new Paint(); | |
} | |
public MyView(Context context, AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
mPaint=new Paint(); | |
} | |
@Override | |
protected void onDraw(Canvas canvas) { | |
super.onDraw(canvas); | |
// canvas.translate(getPaddingLeft(), getPaddingTop() - getPaddingBottom()); | |
canvas.drawPath(makeArrow(), mPaint); | |
} | |
private static Path makeArrow() { | |
Path path=new Path(); | |
path.moveTo(100,500); | |
path.lineTo(300,500); | |
path.lineTo(300,450); | |
path.lineTo(473,550); | |
path.lineTo(300,650); | |
path.lineTo(300,600); | |
path.lineTo(100,600); | |
path.lineTo(100,500); | |
path.close(); | |
return path; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment