public?class?ViewPagerIndicator?extends?LinearLayout?{
????private?Paint?mPaint;
????private?Path?mPath;
????private?int?mTriangleWidth;
????private?int?mTriangleHeight;
????private?static?final?float?RADIO_TRIANGLE_WIDTH?=?1?/?6f;
????private?int?mInitTranslationX;//初始x方向偏移量
????private?int?mTranslationX;//三角形x方向偏移量
????public?ViewPagerIndicator(Context?context)?{
????????this(context,null);
????}
????public?ViewPagerIndicator(Context?context,?AttributeSet?attrs)?{
????????super(context,?attrs);
????????mPaint?=?new?Paint();
????????mPaint.setAntiAlias(true);
????????mPaint.setStyle(Style.FILL);
????????mPaint.setPathEffect(new?CornerPathEffect(3));
????????mPaint.setColor(Color.parseColor("#ffffffff"));
????}
????@Override
????protected?void?dispatchDraw(Canvas?canvas)?{
????????Log.d("ViewPagerIndicator",?"dispatchDraw");
????????canvas.save();
????????canvas.translate(mInitTranslationX?+?mTranslationX,?getHeight()?+?2);
????????canvas.drawPath(mPath,?mPaint);
????????canvas.restore();
????????super.dispatchDraw(canvas);
????}
????@Override
????protected?void?onSizeChanged(int?w,?int?h,?int?oldw,?int?oldh)?{
????????Log.d("ViewPagerIndicator",?"onSizeChanged");
????????super.onSizeChanged(w,?h,?oldw,?oldh);
????????mTriangleWidth?=?(int)?(w?/?3?*?RADIO_TRIANGLE_WIDTH);
????????mInitTranslationX?=?w?/?3?/?2?-?mTriangleWidth?/?2;
????????mTriangleHeight?=?mTriangleWidth?/?2;
????????initTriangle();
????}
????//初始化三角形
????private?void?initTriangle()?{
????????mPath?=?new?Path();
????????mPath.moveTo(0,?0);
????????mPath.moveTo(mTriangleWidth,?0);
????????mPath.moveTo(mTriangleWidth?/?2,-mTriangleHeight);
????????mPath.close();
????}
}
2016-04-03
看你的initTriangle()函數(shù),
void moveTo(float x, float y)
?Set the begining of the next contour to the point (x,y).
這個只是起始點要用到,
后面畫線用void lineTo(float x, float y)函數(shù):
Add a line from the last point to the specified point (x, y).
2016-11-09
我的也是lineto寫成了moveto,感謝
2016-04-02
你的畫筆在哪里呢?