Created
September 15, 2014 12:50
-
-
Save nightbear1009/ad4d9d96faeb7a756931 to your computer and use it in GitHub Desktop.
ToogleDrawableDown draw a triangle using drawable
This file contains hidden or 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.ui; | |
import android.graphics.Canvas; | |
import android.graphics.ColorFilter; | |
import android.graphics.Paint; | |
import android.graphics.Paint.Style; | |
import android.graphics.Path; | |
import android.graphics.Path.FillType; | |
import android.graphics.Point; | |
import android.graphics.RectF; | |
import android.graphics.drawable.Drawable; | |
import android.util.Log; | |
public class ToogleDrawableDown extends Drawable { | |
public ToogleDrawableDown() {} | |
@Override | |
public void draw(Canvas canvas) { | |
// Set the correct values in the Paint | |
Paint paint = new Paint(); | |
paint.setColor(android.graphics.Color.TRANSPARENT); | |
paint.setStyle(Paint.Style.FILL); | |
canvas.drawPaint(paint); | |
int stroke = 4; | |
int paddingLeft =10; | |
double TriBottom = 8.3; | |
double TriHeight = 8.8; | |
paint.setStrokeWidth(4); | |
paint.setColor(android.graphics.Color.RED); | |
paint.setStyle(Paint.Style.FILL_AND_STROKE); | |
paint.setAntiAlias(true); | |
Point a = new Point(paddingLeft+0+stroke, Math.max(canvas.getHeight()/3*2-(int)TriHeight-stroke,0)); | |
Point b = new Point(paddingLeft+(int)TriBottom*2 +stroke, Math.max(canvas.getHeight()/3*2-(int)TriHeight-stroke,0)); | |
Point c = new Point(paddingLeft+(int)TriBottom+stroke, Math.max(canvas.getHeight()/3*2-stroke,0)); | |
Path path = new Path(); | |
path.setFillType(FillType.EVEN_ODD); | |
path.moveTo(a.x, a.y); | |
path.lineTo(b.x, b.y); | |
path.lineTo(c.x, c.y); | |
path.lineTo(a.x, a.y); | |
path.close(); | |
canvas.drawPath(path, paint); | |
} | |
@Override | |
public void setAlpha(int alpha) {} | |
@Override | |
public void setColorFilter(ColorFilter cf) {} | |
@Override | |
public int getOpacity() { | |
// TODO Auto-generated method stub | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment