Code example for Drawable

Methods: drawgetIntrinsicHeightgetIntrinsicWidthsetAlpha

0
    public float getAlpha() { 
        return mAlpha;
    } 
 
    public int getWidth() { 
        return mDrawable != null ? mDrawable.getIntrinsicWidth() : 0;
    } 
 
    public int getHeight() { 
        return mDrawable != null ? mDrawable.getIntrinsicHeight() : 0;
    } 
 
    public void draw(Canvas canvas) {
        if (mDrawable == null) {
            return; 
        } 
        canvas.save(Canvas.MATRIX_SAVE_FLAG);
        canvas.translate(mTranslationX, mTranslationY);
        canvas.scale(mScaleX, mScaleY);
        canvas.translate(-0.5f * getWidth(), -0.5f * getHeight());
        mDrawable.setAlpha((int) Math.round(mAlpha * 255f));
        mDrawable.draw(canvas);
        canvas.restore();
    } 
}