public class RectShape
extends Shape
| java.lang.Object | ||
| android.graphics.drawable.shapes.Shape | ||
| android.graphics.drawable.shapes.RectShape | ||
| |
定义一个矩形形状。 矩形可以得出与自己的draw()方法的画布,但更多的图形控件可用,如果你不是通过RectShape为ShapeDrawable 。
Public constructors |
|
|---|---|
RectShape() |
|
公共方法(Public methods) |
|
|---|---|
RectShape |
clone() 创建并返回此对象的副本。 |
void |
draw(Canvas canvas, Paint paint) 使用提供的Paint将此形状绘制到提供的Canvas中。 |
void |
getOutline(Outline outline) 计算形状的轮廓并将其返回到提供的大纲参数中。 |
Protected methods |
|
|---|---|
void |
onResize(float width, float height) 执行 |
final RectF |
rect() 返回定义此矩形边界的RectF。 |
继承方法(Inherited methods) |
|
|---|---|
android.graphics.drawable.shapes.Shape
|
|
java.lang.Object
|
|
RectShape clone ()
创建并返回此对象的副本。 “复制”的确切含义可能取决于对象的类别。 一般意图是,对于任何对象x ,表达式:
will be true, and that the expression:x.clone() != x
will bex.clone().getClass() == x.getClass()
true, but these are not absolute requirements. While it is typically the case that:
will bex.clone().equals(x)
true, this is not an absolute requirement.
按照惯例,返回的对象应该通过调用super.clone来获得。 如果一个类和它的所有超类( Object除外)都遵守这个约定,那么情况就是x.clone().getClass() == x.getClass() 。
按照惯例,这个方法返回的对象应该独立于这个对象(被克隆)。 要实现这种独立性,可能需要在返回super.clone之前修改返回的对象的一个或多个字段。 通常,这意味着复制包含被克隆对象的内部“深层结构”的任何可变对象,并将这些对象的引用替换为对这些副本的引用。 如果一个类仅包含原始字段或对不可变对象的引用,那么通常情况下不需要修改由super.clone返回的对象中的任何字段。
类Object的方法clone执行特定的克隆操作。 首先,如果该对象的类没有实现接口Cloneable ,则引发CloneNotSupportedException 。 请注意,所有阵列都被视为实现接口Cloneable并且数组类型T[]的clone方法的返回类型为T[] ,其中T是任何引用或基本类型。 否则,此方法创建该对象的类的新实例,并使用该对象的相应字段的内容来初始化其所有字段,就像通过赋值一样; 这些字段的内容本身并不克隆。 因此,此方法执行此对象的“浅拷贝”,而不是“深拷贝”操作。
类 Object本身并不实现接口 Cloneable ,所以在类为 Object的对象上调用 clone方法将导致在运行时抛出异常。
| 返回(Returns) | |
|---|---|
RectShape |
a clone of this instance. |
| 抛出异常(Throws) | |
|---|---|
CloneNotSupportedException |
|
void draw (Canvas canvas, Paint paint)
使用提供的Paint将此形状绘制到提供的Canvas中。 在致电之前,您必须致电resize(float, float) 。
| 参数(Parameters) | |
|---|---|
canvas |
Canvas: the Canvas within which this shape should be drawn |
paint |
Paint: the Paint object that defines this shape's characteristics |
void getOutline (Outline outline)
计算形状的轮廓并将其返回到提供的大纲参数中。 默认实现什么也不做, outline不会改变。
| 参数(Parameters) | |
|---|---|
outline |
Outline: The Outline to be populated with the result. Should not be null. |
void onResize (float width,
float height)
执行 resize(float, float)时 resize(float, float)回调方法。
| 参数(Parameters) | |
|---|---|
width |
float: the new width of the Shape |
height |
float: the new height of the Shape |