Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ExpandableTriangleView extends View {
- private Paint paint;
- private Path path;
- private boolean isExpanded;
- public ExpandableTriangleView(Context context) {
- super(context);
- paint = new Paint();
- paint.setStyle(Paint.Style.FILL);
- paint.setColor(Color.parseColor("#cccccc"));
- paint.setAntiAlias(true);
- }
- public void expand() {
- isExpanded = true;
- path = null;
- invalidate();
- }
- public void collapse() {
- isExpanded = false;
- path = null;
- invalidate();
- }
- @Override
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
- canvas.drawPath(getTrianglePath(), paint);
- }
- private Path getTrianglePath() {
- if (path == null) {
- path = new Path();
- int width = getWidth();
- int height = getHeight();
- if (isExpanded) {
- path.moveTo(0, 0);
- path.lineTo(width, 0);
- path.lineTo(width / 2, height);
- } else {
- path.moveTo(0, 0);
- path.lineTo(0, height);
- path.lineTo(width, height / 2);
- }
- }
- return path;
- }
- }
Add Comment
Please, Sign In to add comment