ArcLayout

@UiThread public class ArcLayout


Container which will lay its elements out on an arc. Elements will be relative to a given anchor angle (where 0 degrees = 12 o clock), where the layout relative to the anchor angle is controlled using anchorAngleDegrees and anchorType. The thickness of the arc is calculated based on the child element with the greatest height (in the case of Android widgets), or greatest thickness (for curved widgets). By default, the container lays its children one by one in clockwise direction. The attribute 'clockwise' can be set to false to make the layout direction as anti-clockwise. These two types of widgets will be drawn as follows.

Standard Android Widgets:

These widgets will be drawn as usual, but placed at the correct position on the arc, with the correct amount of rotation applied. As an example, for an Android Text widget, the text baseline would be drawn at a tangent to the arc. The arc length of a widget is obtained by measuring the width of the widget, and transforming that to the length of an arc on a circle.

A standard Android widget will be measured as usual, but the maximum height constraint will be capped at the minimum radius of the arc (i.e. width / 2).

"Curved" widgets:

Widgets which implement ArcLayout.Widget are expected to draw themselves within an arc automatically. These widgets will be measured with the full dimensions of the arc container. They are also expected to provide their thickness (used when calculating the thickness of the arc) and the current sweep angle (used for laying out when drawing). Note that the ArcLayout will apply a rotation transform to the canvas before drawing this child; the inner child need not perform any rotations itself.

An example of a widget which implements this interface is CurvedTextView, which will lay itself out along the arc.

Summary

Nested types

ArcLayout.LayoutParams

Layout parameters for a widget added to an arc.

ArcLayout.Widget

Interface for a widget which knows it is being rendered inside an arc, and will draw itself accordingly.

Constants

static final @NonNull int

Anchor at the center of the set of elements drawn within this container.

static final @NonNull int

Anchor at the end of the set of elements drawn within this container.

static final @NonNull int

Anchor at the start of the set of elements drawn within this container.

Public constructors

ArcLayout(
    @NonNull Context context,
    @Nullable AttributeSet attrs,
    @NonNull int defStyleAttr
)
ArcLayout(
    @NonNull Context context,
    @Nullable AttributeSet attrs,
    @NonNull int defStyleAttr,
    @NonNull int defStyleRes
)

Public methods

@Override @NonNull ViewGroup.LayoutParams
@FloatRange(from = 0.0, to = 360.0, toInclusive = true) @NonNull float

Returns the anchor angle used for this container, in degrees.

@ArcLayout.AnchorType @NonNull int

Returns the anchor type used for this container.

@NonNull boolean

returns the layout direction

@Override @NonNull boolean
@Override @NonNull boolean
@Override @NonNull void
@NonNull void
setAnchorAngleDegrees(
    @FloatRange(from = 0.0, to = 360.0, toInclusive = true) @NonNull float anchorAngleDegrees
)

Sets the anchor angle used for this container, in degrees.

@NonNull void

Sets the anchor type used for this container.

@NonNull void
setClockwise(@NonNull boolean clockwise)

Sets the layout direction