當前位置: 首頁>>代碼示例>>Java>>正文


Java Drawable.copyBounds方法代碼示例

本文整理匯總了Java中android.graphics.drawable.Drawable.copyBounds方法的典型用法代碼示例。如果您正苦於以下問題:Java Drawable.copyBounds方法的具體用法?Java Drawable.copyBounds怎麽用?Java Drawable.copyBounds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.graphics.drawable.Drawable的用法示例。


在下文中一共展示了Drawable.copyBounds方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: drawImage

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public static void drawImage(Canvas canvas,
                             Drawable drawable,
                             int x, int y,
                             int width, int height) {

    MPPointF drawOffset = MPPointF.getInstance();
    drawOffset.x = x - (width / 2);
    drawOffset.y = y - (height / 2);

    drawable.copyBounds(mDrawableBoundsCache);
    drawable.setBounds(
            mDrawableBoundsCache.left,
            mDrawableBoundsCache.top,
            mDrawableBoundsCache.left + width,
            mDrawableBoundsCache.top + width);

    int saveId = canvas.save();
    // translate to the correct position and draw
    canvas.translate(drawOffset.x, drawOffset.y);
    drawable.draw(canvas);
    canvas.restoreToCount(saveId);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:Utils.java

示例2: getDrawableBounds

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
protected static Rect getDrawableBounds(Drawable d) {
    Rect bounds = new Rect();
    d.copyBounds(bounds);
    if (bounds.width() == 0 || bounds.height() == 0) {
        bounds.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
    } else {
        bounds.offsetTo(0, 0);
    }
    return bounds;
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:11,代碼來源:DragPreviewProvider.java

示例3: Bouncer

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public Bouncer(
        final Drawable drawable,
        final int speedX,
        final int speedY) {

    this.drawable = drawable;
    this.bounds = drawable.copyBounds();
    this.speedX = speedX;
    this.speedY = speedY;
}
 
開發者ID:PacktPublishing,項目名稱:Hands-On-Android-UI-Development,代碼行數:11,代碼來源:BouncingDrawablesView.java

示例4: getDrawableBounds

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
protected static Rect getDrawableBounds(Drawable d) {
    Rect bounds = new Rect();
    d.copyBounds(bounds);
    if (bounds.width() == 0 || bounds.height() == 0) {
        bounds.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
    } else {
        bounds.offsetTo(0, 0);
    }
    if (d instanceof PreloadIconDrawable) {
        int inset = -((PreloadIconDrawable) d).getOutset();
        bounds.inset(inset, inset);
    }
    return bounds;
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:15,代碼來源:DragPreviewProvider.java

示例5: onDraw

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
protected void onDraw(Canvas canvas) {
    int saveCount;
    Layout switchText;
    super.onDraw(canvas);
    Rect padding = this.mTempRect;
    Drawable trackDrawable = this.mTrackDrawable;
    if (trackDrawable != null) {
        trackDrawable.getPadding(padding);
    } else {
        padding.setEmpty();
    }
    int switchTop = this.mSwitchTop;
    int switchInnerTop = switchTop + padding.top;
    int switchInnerBottom = this.mSwitchBottom - padding.bottom;
    Drawable thumbDrawable = this.mThumbDrawable;
    if (trackDrawable != null) {
        if (!this.mSplitTrack || thumbDrawable == null) {
            trackDrawable.draw(canvas);
        } else {
            Rect insets = DrawableUtils.getOpticalBounds(thumbDrawable);
            thumbDrawable.copyBounds(padding);
            padding.left += insets.left;
            padding.right -= insets.right;
            saveCount = canvas.save();
            canvas.clipRect(padding, Op.DIFFERENCE);
            trackDrawable.draw(canvas);
            canvas.restoreToCount(saveCount);
        }
    }
    saveCount = canvas.save();
    if (thumbDrawable != null) {
        thumbDrawable.draw(canvas);
    }
    if (getTargetCheckedState()) {
        switchText = this.mOnLayout;
    } else {
        switchText = this.mOffLayout;
    }
    if (switchText != null) {
        int cX;
        int[] drawableState = getDrawableState();
        if (this.mTextColors != null) {
            this.mTextPaint.setColor(this.mTextColors.getColorForState(drawableState, 0));
        }
        this.mTextPaint.drawableState = drawableState;
        if (thumbDrawable != null) {
            Rect bounds = thumbDrawable.getBounds();
            cX = bounds.left + bounds.right;
        } else {
            cX = getWidth();
        }
        canvas.translate((float) ((cX / 2) - (switchText.getWidth() / 2)), (float) (((switchInnerTop + switchInnerBottom) / 2) - (switchText.getHeight() / 2)));
        switchText.draw(canvas);
    }
    canvas.restoreToCount(saveCount);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:57,代碼來源:SwitchCompat.java


注:本文中的android.graphics.drawable.Drawable.copyBounds方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。