Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)
Android APIs
public abstract class

Shape

extends Object
implements Cloneable
java.lang.Object
   ↳ android.graphics.drawable.shapes.Shape
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Defines a generic graphical "shape." Any Shape can be drawn to a Canvas with its own draw() method, but more graphical control is available if you instead pass it to a ShapeDrawable .

Summary

Public Constructors
Shape ()
Public Methods
Shape clone ()
Creates and returns a copy of this Object .
abstract void draw ( Canvas canvas, Paint paint)
Draw this shape into the provided Canvas, with the provided Paint.
final float getHeight ()
Returns the height of the Shape.
final float getWidth ()
Returns the width of the Shape.
boolean hasAlpha ()
Checks whether the Shape is opaque.
final void resize (float width, float height)
Resizes the dimensions of this shape.
Protected Methods
void onResize (float width, float height)
Callback method called when resize(float, float) is executed.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public Shape ()

Added in API level 1

Public Methods

public Shape clone ()

Added in API level 1

Creates and returns a copy of this Object . The default implementation returns a so-called "shallow" copy: It creates a new instance of the same class and then copies the field values (including object references) from this instance to the new instance. A "deep" copy, in contrast, would also recursively clone nested objects. A subclass that needs to implement this kind of cloning should call super.clone() to create the new instance and then create deep copies of the nested, mutable objects.

Returns
  • a copy of this object.

public abstract void draw ( Canvas canvas, Paint paint)

Added in API level 1

Draw this shape into the provided Canvas, with the provided Paint. Before calling this, you must call resize(float, float) .

Parameters
canvas the Canvas within which this shape should be drawn
paint the Paint object that defines this shape's characteristics

public final float getHeight ()

Added in API level 1

Returns the height of the Shape.

public final float getWidth ()

Added in API level 1

Returns the width of the Shape.

public boolean hasAlpha ()

Added in API level 1

Checks whether the Shape is opaque. Default impl returns true. Override if your subclass can be opaque.

Returns
  • true if any part of the drawable is not opaque.

public final void resize (float width, float height)

Added in API level 1

Resizes the dimensions of this shape. Must be called before draw(Canvas, Paint) .

Parameters
width the width of the shape (in pixels)
height the height of the shape (in pixels)

Protected Methods

protected void onResize (float width, float height)

Added in API level 1

Callback method called when resize(float, float) is executed.

Parameters
width the new width of the Shape
height the new height of the Shape