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


Java Drawable.getBounds方法代碼示例

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


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

示例1: createDrawableBitmap

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private static Bitmap createDrawableBitmap(Drawable drawable) {
    int width = drawable.getIntrinsicWidth();
    int height = drawable.getIntrinsicHeight();
    if (width <= 0 || height <= 0) {
        return null;
    }
    float scale = Math.min(1.0f, ((float) MAX_IMAGE_SIZE) / ((float) (width * height)));
    if ((drawable instanceof BitmapDrawable) && scale == 1.0f) {
        return ((BitmapDrawable) drawable).getBitmap();
    }
    int bitmapWidth = (int) (((float) width) * scale);
    int bitmapHeight = (int) (((float) height) * scale);
    Bitmap bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Rect existingBounds = drawable.getBounds();
    int left = existingBounds.left;
    int top = existingBounds.top;
    int right = existingBounds.right;
    int bottom = existingBounds.bottom;
    drawable.setBounds(0, 0, bitmapWidth, bitmapHeight);
    drawable.draw(canvas);
    drawable.setBounds(left, top, right, bottom);
    return bitmap;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:25,代碼來源:SharedElementCallback.java

示例2: draw

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
public void draw(@NonNull final Canvas canvas, final CharSequence text,
                 final int start, final int end, final float x,
                 final int top, final int y, final int bottom, @NonNull final Paint paint) {
    Drawable d = getCachedDrawable();
    Rect rect = d.getBounds();
    canvas.save();
    final float fontHeight = paint.getFontMetrics().descent - paint.getFontMetrics().ascent;
    int transY = bottom - rect.bottom;
    if (rect.height() < fontHeight) { // this is the fucking code which I waste 3 days
        if (mVerticalAlignment == ALIGN_BASELINE) {
            transY -= paint.getFontMetricsInt().descent;
        } else if (mVerticalAlignment == ALIGN_CENTER) {
            transY -= (fontHeight - rect.height()) / 2;
        } else if (mVerticalAlignment == ALIGN_TOP) {
            transY -= fontHeight - rect.height();
        }
    }
    canvas.translate(x, transY);
    d.draw(canvas);
    canvas.restore();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:SpanUtils.java

示例3: initIndicatorRect

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
 * The size of the indicator is same as the content region of the {@link #mBgDrawable} minus
 * half the stroke size to accommodate the indicator.
 */
private void initIndicatorRect() {
    Drawable d = mBgDrawable;
    Rect bounds = d.getBounds();

    d.getPadding(sTempRect);
    // Amount by which padding has to be scaled
    float paddingScaleX = ((float) bounds.width()) / d.getIntrinsicWidth();
    float paddingScaleY = ((float) bounds.height()) / d.getIntrinsicHeight();
    mIndicatorRect.set(
            bounds.left + sTempRect.left * paddingScaleX,
            bounds.top + sTempRect.top * paddingScaleY,
            bounds.right - sTempRect.right * paddingScaleX,
            bounds.bottom - sTempRect.bottom * paddingScaleY);

    float inset = mPaint.getStrokeWidth() / 2;
    mIndicatorRect.inset(inset, inset);
    mIndicatorRectDirty = false;
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:23,代碼來源:PreloadIconDrawable.java

示例4: draw

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas, CharSequence text, int start, int end,
		float x, int top, int y, int bottom, Paint paint) {
	// super.draw(canvas, text, start, end, x, top, y, bottom, paint);
	Drawable b = getCachedDrawable();
	canvas.save();

	int transY = bottom - b.getBounds().bottom;
	if (mVerticalAlignment == ALIGN_BASELINE) {
		transY = top + ((bottom - top) / 2)
				- ((b.getBounds().bottom - b.getBounds().top) / 2) - mTop;
	}

	canvas.translate(x, transY);
	b.draw(canvas);
	canvas.restore();
}
 
開發者ID:lennyup,項目名稱:react-native-udesk,代碼行數:18,代碼來源:EmojiconSpan.java

示例5: getSize

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
public int getSize(@NonNull final Paint paint, final CharSequence text,
                   final int start, final int end,
                   final Paint.FontMetricsInt fm) {
    Drawable d = getCachedDrawable();
    Rect rect = d.getBounds();
    final int fontHeight = (int) (paint.getFontMetrics().descent - paint.getFontMetrics().ascent);
    if (fm != null) { // this is the fucking code which I waste 3 days
        if (rect.height() > fontHeight) {
            if (mVerticalAlignment == ALIGN_TOP) {
                fm.descent += rect.height() - fontHeight;
            } else if (mVerticalAlignment == ALIGN_CENTER) {
                fm.ascent -= (rect.height() - fontHeight) / 2;
                fm.descent += (rect.height() - fontHeight) / 2;
            } else {
                fm.ascent -= rect.height() - fontHeight;
            }
        }
    }
    return rect.right;
}
 
開發者ID:Wilshion,項目名稱:HeadlineNews,代碼行數:22,代碼來源:SpanUtils.java

示例6: draw

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
    public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
        //super.draw(canvas, text, start, end, x, top, y, bottom, paint);
        Drawable b = getCachedDrawable();
        int count = canvas.save();

//        int transY = fontMetricesBottom - b.getBounds().bottom;
//        int transY -= paint.getFontMetricsInt().descent;

        // 因為 TextView 加了 lineSpacing 之後會導致這裏的 bottom、top 參數與單行情況不一樣,所以不用 bottom、top,而使用 fontMetrics 的高度來計算
        int fontMetricesTop = y + paint.getFontMetricsInt().top;
        int fontMetricesBottom = fontMetricesTop + (paint.getFontMetricsInt().bottom - paint.getFontMetricsInt().top);
        int transY = fontMetricesTop + ((fontMetricesBottom - fontMetricesTop) / 2) - ((b.getBounds().bottom - b.getBounds().top) / 2) - mTop;

        transY += mTranslateY;

        canvas.translate(x, transY);
        b.draw(canvas);
        canvas.restoreToCount(count);
    }
 
開發者ID:coopese,項目名稱:qmui,代碼行數:21,代碼來源:EmojiconSpan.java

示例7: getSize

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
public int getSize(Paint paint, CharSequence text,
                   int start, int end,
                   Paint.FontMetricsInt fm) {
    Drawable d = getCachedDrawable();
    Rect rect = d.getBounds();

    if (fm != null) {
        // Centers the text with the ImageSpan
        if ((rect.bottom - (fm.descent - fm.ascent)) >= 0) {
            // Stores the initial descent and computes the margin available
            initialDescent = fm.descent;
            extraSpace = rect.bottom - (fm.descent - fm.ascent);
        }

        fm.descent = extraSpace / 2 + initialDescent;
        fm.bottom = fm.descent;

        fm.ascent = -rect.bottom + fm.descent;
        fm.top = fm.ascent;
    }

    return rect.right;
}
 
開發者ID:ceji-longquan,項目名稱:ceji_android,代碼行數:25,代碼來源:CenteredImageSpan.java

示例8: onDrawKeyBackground

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
protected void onDrawKeyBackground(@NonNull final Key key, @NonNull final Canvas canvas,
        @NonNull final Drawable background) {
    final int keyWidth = key.getDrawWidth();
    final int keyHeight = key.getHeight();
    final int bgWidth, bgHeight, bgX, bgY;
    if (key.needsToKeepBackgroundAspectRatio(mDefaultKeyLabelFlags)
            // HACK: To disable expanding normal/functional key background.
            && !key.hasCustomActionLabel()) {
        final int intrinsicWidth = background.getIntrinsicWidth();
        final int intrinsicHeight = background.getIntrinsicHeight();
        final float minScale = Math.min(
                keyWidth / (float)intrinsicWidth, keyHeight / (float)intrinsicHeight);
        bgWidth = (int)(intrinsicWidth * minScale);
        bgHeight = (int)(intrinsicHeight * minScale);
        bgX = (keyWidth - bgWidth) / 2;
        bgY = (keyHeight - bgHeight) / 2;
    } else {
        final Rect padding = mKeyBackgroundPadding;
        bgWidth = keyWidth + padding.left + padding.right;
        bgHeight = keyHeight + padding.top + padding.bottom;
        bgX = -padding.left;
        bgY = -padding.top;
    }
    final Rect bounds = background.getBounds();
    if (bgWidth != bounds.right || bgHeight != bounds.bottom) {
        background.setBounds(0, 0, bgWidth, bgHeight);
    }
    canvas.translate(bgX, bgY);
    background.draw(canvas);
    canvas.translate(-bgX, -bgY);
}
 
開發者ID:rkkr,項目名稱:simple-keyboard,代碼行數:32,代碼來源:KeyboardView.java

示例9: draw

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
public void draw(@NonNull Canvas canvas, CharSequence text,
                 int start, int end, float x,
                 int top, int y, int bottom, @NonNull Paint paint) {
    Drawable d = getCachedDrawable();
    Rect rect = d.getBounds();
    canvas.save();
    final float fontHeight = paint.getFontMetrics().descent - paint.getFontMetrics().ascent;
    int transY = bottom - rect.bottom;
    if (rect.height() < fontHeight) { // this is the fucking code which I waste 3 days
        if (mVerticalAlignment == ALIGN_BASELINE) {
            transY -= paint.getFontMetricsInt().descent;
        } else if (mVerticalAlignment == ALIGN_CENTER) {
            transY -= (fontHeight - rect.height()) / 2;
        } else if (mVerticalAlignment == ALIGN_TOP) {
            transY -= fontHeight - rect.height();
        }
    }
    canvas.translate(x, transY);
    float v = paint.measureText(text, start, end);

    d.draw(canvas);
    paint.measureText(text, start, end);
    canvas.restore();
}
 
開發者ID:pan2yong22,項目名稱:AndroidUtilCode-master,代碼行數:26,代碼來源:SpanUtils.java

示例10: getActivityLaunchOptions

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private Bundle getActivityLaunchOptions(View v) {
    if (Utilities.ATLEAST_MARSHMALLOW) {
        int left = 0, top = 0;
        int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
        if (v instanceof TextView) {
            // Launch from center of icon, not entire view
            Drawable icon = Workspace.getTextViewIcon((TextView) v);
            if (icon != null) {
                Rect bounds = icon.getBounds();
                left = (width - bounds.width()) / 2;
                top = v.getPaddingTop();
                width = bounds.width();
                height = bounds.height();
            }
        }
        return ActivityOptions.makeClipRevealAnimation(v, left, top, width, height).toBundle();
    } else if (Utilities.ATLEAST_LOLLIPOP_MR1) {
        // On L devices, we use the device default slide-up transition.
        // On L MR1 devices, we use a custom version of the slide-up transition which
        // doesn't have the delay present in the device default.
        return ActivityOptions.makeCustomAnimation(
                this, R.anim.task_open_enter, R.anim.no_anim).toBundle();
    }
    return null;
}
 
開發者ID:TeamBrainStorm,項目名稱:SimpleUILauncher,代碼行數:26,代碼來源:Launcher.java

示例11: draw

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
    Drawable drawable = getDrawable();
    canvas.save();
    int transY = ((bottom - top) - drawable.getBounds().bottom) / 2 + top;
    canvas.translate(x, transY);
    drawable.draw(canvas);
    canvas.restore();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:EmoticonSpan.java

示例12: onFinalImageSet

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
public void onFinalImageSet(
    String id,
    ImageInfo imageInfo,
    Animatable animatable) {
  if (mEnableResizing &&
      imageInfo != null &&
      mDraweeSpan.getDraweeHolder().getTopLevelDrawable() != null) {
    Drawable topLevelDrawable = mDraweeSpan.getDraweeHolder().getTopLevelDrawable();
    Rect topLevelDrawableBounds = topLevelDrawable.getBounds();
    if (mFixedHeight != UNSET_SIZE) {
      float imageWidth = ((float) mFixedHeight / imageInfo.getHeight()) * imageInfo.getWidth();
      int imageWidthPx = (int) imageWidth;
      if (topLevelDrawableBounds.width() != imageWidthPx ||
          topLevelDrawableBounds.height() != mFixedHeight) {
        topLevelDrawable.setBounds(0, 0, imageWidthPx, mFixedHeight);

        if (mDraweeSpanChangedListener != null) {
          mDraweeSpanChangedListener.onDraweeSpanChanged(DraweeSpanStringBuilder.this);
        }
      }
    } else if (topLevelDrawableBounds.width() != imageInfo.getWidth() ||
        topLevelDrawableBounds.height() != imageInfo.getHeight()) {
      topLevelDrawable.setBounds(0, 0, imageInfo.getWidth(), imageInfo.getHeight());

      if (mDraweeSpanChangedListener != null) {
        mDraweeSpanChangedListener.onDraweeSpanChanged(DraweeSpanStringBuilder.this);
      }
    }
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:32,代碼來源:DraweeSpanStringBuilder.java

示例13: resetLayout

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
void resetLayout() {
    mContent.removeAllViewsInLayout();

    // 在hotseat中顯示進入所有應用列表的圖標
    if (!FeatureFlags.NO_ALL_APPS_ICON) {
        // Add the Apps button
        Context context = getContext();
        int allAppsButtonRank = mLauncher.getDeviceProfile().inv.getAllAppsButtonRank();

        LayoutInflater inflater = LayoutInflater.from(context);
        TextView allAppsButton = (TextView)
                inflater.inflate(R.layout.all_apps_button, mContent, false);
        Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon);

        mLauncher.resizeIconDrawable(d);
        int scaleDownPx = getResources().getDimensionPixelSize(R.dimen.all_apps_button_scale_down);
        Rect bounds = d.getBounds();
        d.setBounds(bounds.left, bounds.top + scaleDownPx / 2, bounds.right - scaleDownPx,
                bounds.bottom - scaleDownPx / 2);
        allAppsButton.setCompoundDrawables(null, d, null, null);

        allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
        allAppsButton.setOnKeyListener(new HotseatIconKeyEventListener());
        if (mLauncher != null) {
            mLauncher.setAllAppsButton(allAppsButton);
            allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener());
            allAppsButton.setOnClickListener(mLauncher);
            allAppsButton.setOnLongClickListener(mLauncher);
            allAppsButton.setOnFocusChangeListener(mLauncher.mFocusHandler);
        }

        // Note: We do this to ensure that the hotseat is always laid out in the orientation of
        // the hotseat in order regardless of which orientation they were added
        int x = getCellXFromOrder(allAppsButtonRank);
        int y = getCellYFromOrder(allAppsButtonRank);
        CellLayout.LayoutParams lp = new CellLayout.LayoutParams(x, y, 1, 1);
        lp.canReorder = false;
        mContent.addViewToCellLayout(allAppsButton, -1, allAppsButton.getId(), lp, true);
    }
}
 
開發者ID:TeamBrainStorm,項目名稱:SimpleUILauncher,代碼行數:41,代碼來源:Hotseat.java

示例14: resetLayout

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
void resetLayout() {
    mContent.removeAllViewsInLayout();

    if (!FeatureFlags.NO_ALL_APPS_ICON) {
        // Add the Apps button
        Context context = getContext();
        int allAppsButtonRank = mLauncher.getDeviceProfile().inv.getAllAppsButtonRank();

        LayoutInflater inflater = LayoutInflater.from(context);
        TextView allAppsButton = (TextView)
                inflater.inflate(R.layout.all_apps_button, mContent, false);
        Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon);

        mLauncher.resizeIconDrawable(d);
        int scaleDownPx = getResources().getDimensionPixelSize(R.dimen.all_apps_button_scale_down);
        Rect bounds = d.getBounds();
        d.setBounds(bounds.left, bounds.top + scaleDownPx / 2, bounds.right - scaleDownPx,
                bounds.bottom - scaleDownPx / 2);
        allAppsButton.setCompoundDrawables(null, d, null, null);

        allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
        allAppsButton.setOnKeyListener(new HotseatIconKeyEventListener());
        if (mLauncher != null) {
            mLauncher.setAllAppsButton(allAppsButton);
            allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener());
            allAppsButton.setOnClickListener(mLauncher);
            allAppsButton.setOnLongClickListener(mLauncher);
            allAppsButton.setOnFocusChangeListener(mLauncher.mFocusHandler);
        }

        // Note: We do this to ensure that the hotseat is always laid out in the orientation of
        // the hotseat in order regardless of which orientation they were added
        int x = getCellXFromOrder(allAppsButtonRank);
        int y = getCellYFromOrder(allAppsButtonRank);
        CellLayout.LayoutParams lp = new CellLayout.LayoutParams(x, y, 1, 1);
        lp.canReorder = false;
        mContent.addViewToCellLayout(allAppsButton, -1, allAppsButton.getId(), lp, true);
    }
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:40,代碼來源:Hotseat.java

示例15: getSize

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
    if (mAvoidSuperChangeFontMetrics) {
        Drawable d = getDrawable();
        Rect rect = d.getBounds();
        mWidth = rect.right;
    } else {
        mWidth = super.getSize(paint, text, start, end, fm);
    }
    if (mFontWidthMultiple > 0) {
        mWidth = (int) (paint.measureText("子") * mFontWidthMultiple);
    }
    return mWidth;
}
 
開發者ID:QMUI,項目名稱:QMUI_Android,代碼行數:15,代碼來源:QMUIAlignMiddleImageSpan.java


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