IT. Expert System.

Android Reference

GradientDrawable


android.graphics.drawable

Class GradientDrawable



  • public class GradientDrawable
    extends Drawable
    A Drawable with a color gradient for buttons, backgrounds, etc.

    It can be defined in an XML file with the <shape> element. For more information, see the guide to Drawable Resources.

    • Constructor Detail

      • GradientDrawable

        public GradientDrawable()
      • GradientDrawable

        public GradientDrawable(GradientDrawable.Orientation orientation,
                        int[] colors)
        Create a new gradient drawable given an orientation and an array of colors for the gradient.
    • Method Detail

      • getPadding

        public boolean getPadding(Rect padding)
        Description copied from class: Drawable
        Return in padding the insets suggested by this Drawable for placing content inside the drawable's bounds. Positive values move toward the center of the Drawable (set Rect.inset). Returns true if this drawable actually has a padding, else false. When false is returned, the padding is always set to 0.
        Overrides:
        getPadding in class Drawable
      • setCornerRadii

        public void setCornerRadii(float[] radii)

        Specify radii for each of the 4 corners. For each corner, the array contains 2 values, [X_radius, Y_radius]. The corners are ordered top-left, top-right, bottom-right, bottom-left. This property is honored only when the shape is of type RECTANGLE.

        Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate() before changing this property.

        Parameters:
        radii - 4 pairs of X and Y radius for each corner, specified in pixels. The length of this array must be >= 8
        See Also:
        mutate(), setCornerRadii(float[]), setShape(int)
      • setCornerRadius

        public void setCornerRadius(float radius)

        Specify radius for the corners of the gradient. If this is > 0, then the drawable is drawn in a round-rectangle, rather than a rectangle. This property is honored only when the shape is of type RECTANGLE.

        Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate() before changing this property.

        Parameters:
        radius - The radius in pixels of the corners of the rectangle shape
        See Also:
        mutate(), setCornerRadii(float[]), setShape(int)
      • setStroke

        public void setStroke(int width,
                     int color)

        Set the stroke width and color for the drawable. If width is zero, then no stroke is drawn.

        Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate() before changing this property.

        Parameters:
        width - The width in pixels of the stroke
        color - The color of the stroke
        See Also:
        mutate(), setStroke(int, int, float, float)
      • setStroke

        public void setStroke(int width,
                     int color,
                     float dashWidth,
                     float dashGap)

        Set the stroke width and color for the drawable. If width is zero, then no stroke is drawn. This method can also be used to dash the stroke.

        Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate() before changing this property.

        Parameters:
        width - The width in pixels of the stroke
        color - The color of the stroke
        dashWidth - The length in pixels of the dashes, set to 0 to disable dashes
        dashGap - The gap in pixels between dashes
        See Also:
        mutate(), setStroke(int, int)
      • setSize

        public void setSize(int width,
                   int height)

        Sets the size of the shape drawn by this drawable.

        Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate() before changing this property.

        Parameters:
        width - The width of the shape used by this drawable
        height - The height of the shape used by this drawable
        See Also:
        mutate(), setGradientType(int)
      • setShape

        public void setShape(int shape)

        Sets the type of shape used to draw the gradient.

        Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate() before changing this property.

        Parameters:
        shape - The desired shape for this drawable: LINE, OVAL, RECTANGLE or RING
        See Also:
        mutate()
      • setGradientType

        public void setGradientType(int gradient)

        Sets the type of gradient used by this drawable..

        Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate() before changing this property.

        Parameters:
        gradient - The type of the gradient: LINEAR_GRADIENT, RADIAL_GRADIENT or SWEEP_GRADIENT
        See Also:
        mutate()
      • setGradientCenter

        public void setGradientCenter(float x,
                             float y)

        Sets the center location of the gradient. The radius is honored only when the gradient type is set to RADIAL_GRADIENT or SWEEP_GRADIENT.

        Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate() before changing this property.

        Parameters:
        x - The x coordinate of the gradient's center
        y - The y coordinate of the gradient's center
        See Also:
        mutate(), setGradientType(int)
      • setGradientRadius

        public void setGradientRadius(float gradientRadius)

        Sets the radius of the gradient. The radius is honored only when the gradient type is set to RADIAL_GRADIENT.

        Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate() before changing this property.

        Parameters:
        gradientRadius - The radius of the gradient in pixels
        See Also:
        mutate(), setGradientType(int)
      • setUseLevel

        public void setUseLevel(boolean useLevel)

        Sets whether or not this drawable will honor its level property.

        Note: changing this property will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate() before changing this property.

        Parameters:
        useLevel - True if this drawable should honor its level, false otherwise
        See Also:
        mutate(), Drawable.setLevel(int), Drawable.getLevel()
      • setOrientation

        public void setOrientation(GradientDrawable.Orientation orientation)

        Changes the orientation of the gradient defined in this drawable.

        Note: changing orientation will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate() before changing the orientation.

        Parameters:
        orientation - The desired orientation (angle) of the gradient
        See Also:
        mutate()
      • setColors

        public void setColors(int[] colors)

        Sets the colors used to draw the gradient. Each color is specified as an ARGB integer and the array must contain at least 2 colors.

        Note: changing orientation will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate() before changing the orientation.

        Parameters:
        colors - 2 or more ARGB colors
        See Also:
        mutate(), setColor(int)
      • draw

        public void draw(Canvas canvas)
        Description copied from class: Drawable
        Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter).
        Specified by:
        draw in class Drawable
        Parameters:
        canvas - The canvas to draw into
      • setColor

        public void setColor(int argb)

        Changes this drawbale to use a single color instead of a gradient.

        Note: changing color will affect all instances of a drawable loaded from a resource. It is recommended to invoke mutate() before changing the color.

        Parameters:
        argb - The color used to fill the shape
        See Also:
        mutate(), setColors(int[])
      • getChangingConfigurations

        public int getChangingConfigurations()
        Description copied from class: Drawable
        Return a mask of the configuration parameters for which this drawable may change, requiring that it be re-created. The default implementation returns whatever was provided through Drawable.setChangingConfigurations(int) or 0 by default. Subclasses may extend this to or in the changing configurations of any other drawables they hold.
        Overrides:
        getChangingConfigurations in class Drawable
        Returns:
        Returns a mask of the changing configuration parameters, as defined by Configuration.
        See Also:
        Configuration
      • setAlpha

        public void setAlpha(int alpha)
        Description copied from class: Drawable
        Specify an alpha value for the drawable. 0 means fully transparent, and 255 means fully opaque.
        Specified by:
        setAlpha in class Drawable
      • setDither

        public void setDither(boolean dither)
        Description copied from class: Drawable
        Set to true to have the drawable dither its colors when drawn to a device with fewer than 8-bits per color component. This can improve the look on those devices, but can also slow down the drawing a little.
        Overrides:
        setDither in class Drawable
      • setColorFilter

        public void setColorFilter(ColorFilter cf)
        Description copied from class: Drawable
        Specify an optional colorFilter for the drawable. Pass null to remove any filters.
        Specified by:
        setColorFilter in class Drawable
      • onBoundsChange

        protected void onBoundsChange(Rect r)
        Description copied from class: Drawable
        Override this in your subclass to change appearance if you recognize the specified state.
        Overrides:
        onBoundsChange in class Drawable
      • onLevelChange

        protected boolean onLevelChange(int level)
        Description copied from class: Drawable
        Override this in your subclass to change appearance if you vary based on level.
        Overrides:
        onLevelChange in class Drawable
        Returns:
        Returns true if the level change has caused the appearance of the Drawable to change (that is, it needs to be drawn), else false if it looks the same and there is no need to redraw it since its last level.
      • getIntrinsicWidth

        public int getIntrinsicWidth()
        Description copied from class: Drawable
        Return the intrinsic width of the underlying drawable object. Returns -1 if it has no intrinsic width, such as with a solid color.
        Overrides:
        getIntrinsicWidth in class Drawable
      • getIntrinsicHeight

        public int getIntrinsicHeight()
        Description copied from class: Drawable
        Return the intrinsic height of the underlying drawable object. Returns -1 if it has no intrinsic height, such as with a solid color.
        Overrides:
        getIntrinsicHeight in class Drawable
      • mutate

        public Drawable mutate()
        Description copied from class: Drawable
        Make this drawable mutable. This operation cannot be reversed. A mutable drawable is guaranteed to not share its state with any other drawable. This is especially useful when you need to modify properties of drawables loaded from resources. By default, all drawables instances loaded from the same resource share a common state; if you modify the state of one instance, all the other instances will receive the same modification. Calling this method on a mutable Drawable will have no effect.
        Overrides:
        mutate in class Drawable
        Returns:
        This drawable.
        See Also:
        Drawable.ConstantState, Drawable.getConstantState()


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 1693 / 96487492. Delta: 0.04771 с