Google is committed to advancing racial equity for Black communities. See how.

WearArcLayout

@UiThread open class WearArcLayout : ViewGroup
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ androidx.wear.widget.WearArcLayout

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 ArcLayoutWidget 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 WearArcLayout 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 WearCurvedTextView, which will lay itself out along the arc.

Summary

Nested classes
abstract

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

open

Layout parameters for a widget added to an arc.

Constants
static Int

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

static Int

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

static Int

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

Public constructors
<init>(@NonNull context: Context)

<init>(@NonNull context: Context, @Nullable attrs: AttributeSet?)

<init>(@NonNull context: Context, @Nullable attrs: AttributeSet?, defStyleAttr: Int)

<init>(@NonNull context: Context, @Nullable attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int)

Public methods
open LayoutParams

open Float

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

open Int

Returns the anchor type used for this container.

open Boolean

returns the layout direction

open Unit
setAnchorAngleDegrees(anchorAngleDegrees: Float)

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

open Unit
setAnchorType(anchorType: Int)

Sets the anchor type used for this container.

open Unit
setClockwise(clockwise: Boolean)

Sets the layout direction

Protected methods
open Boolean

open Unit
dispatchDraw(@NonNull canvas: Canvas)

open Boolean
drawChild(@NonNull canvas: Canvas, @NonNull child: View, drawingTime: Long)

open LayoutParams

open LayoutParams

open Unit
onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int)

open Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)

Constants

ANCHOR_CENTER

static val ANCHOR_CENTER: Int

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

As an example, if this container contains two arcs, one having 10 degrees of sweep and the other having 20 degrees of sweep, the first will be drawn between -15 and -5 degrees, and the second between -5 and 15 degrees.

Value: 1

ANCHOR_END

static val ANCHOR_END: Int

Anchor at the end of the set of elements drawn within this container. This causes the last element to end at anchorAngle degrees, with the other elements swept to the left.

As an example, if this container contains two arcs, one having 10 degrees of sweep and the other having 20 degrees of sweep, the first will be drawn between -30 and -20 degrees, and the second between -20 and 0 degrees.

Value: 2

ANCHOR_START

static val ANCHOR_START: Int

Anchor at the start of the set of elements drawn within this container. This causes the first child to be drawn from anchorAngle degrees, to the right.

As an example, if this container contains two arcs, one having 10 degrees of sweep and the other having 20 degrees of sweep, the first will be drawn between 0-10 degrees, and the second between 10-30 degrees.

Value: 0

Public constructors

<init>

WearArcLayout(@NonNull context: Context)

<init>

WearArcLayout(
    @NonNull context: Context,
    @Nullable attrs: AttributeSet?)

<init>

WearArcLayout(
    @NonNull context: Context,
    @Nullable attrs: AttributeSet?,
    defStyleAttr: Int)

<init>

WearArcLayout(
    @NonNull context: Context,
    @Nullable attrs: AttributeSet?,
    defStyleAttr: Int,
    defStyleRes: Int)

Public methods

generateLayoutParams

@NonNull open fun generateLayoutParams(@NonNull attrs: AttributeSet): LayoutParams

getAnchorAngleDegrees

open fun getAnchorAngleDegrees(): Float

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

getAnchorType

open fun getAnchorType(): Int

Returns the anchor type used for this container.

getClockwise

open fun getClockwise(): Boolean

returns the layout direction

setAnchorAngleDegrees

open fun setAnchorAngleDegrees(anchorAngleDegrees: Float): Unit

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

setAnchorType

open fun setAnchorType(anchorType: Int): Unit

Sets the anchor type used for this container.

setClockwise

open fun setClockwise(clockwise: Boolean): Unit

Sets the layout direction

Protected methods

checkLayoutParams

protected open fun checkLayoutParams(@NonNull p: LayoutParams): Boolean

dispatchDraw

protected open fun dispatchDraw(@NonNull canvas: Canvas): Unit

drawChild

protected open fun drawChild(
    @NonNull canvas: Canvas,
    @NonNull child: View,
    drawingTime: Long
): Boolean

generateDefaultLayoutParams

@NonNull protected open fun generateDefaultLayoutParams(): LayoutParams

generateLayoutParams

@NonNull protected open fun generateLayoutParams(@NonNull p: LayoutParams): LayoutParams

onLayout

protected open fun onLayout(
    changed: Boolean,
    l: Int,
    t: Int,
    r: Int,
    b: Int
): Unit

onMeasure

protected open fun onMeasure(
    widthMeasureSpec: Int,
    heightMeasureSpec: Int
): Unit