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


Java Drawable.setBounds方法代碼示例

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


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

示例1: drawable2Bitmap

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private static Bitmap drawable2Bitmap(final Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        if (bitmapDrawable.getBitmap() != null) {
            return bitmapDrawable.getBitmap();
        }
    }
    Bitmap bitmap;
    if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
        bitmap = Bitmap.createBitmap(1, 1,
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    } else {
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    }
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}
 
開發者ID:Wilshion,項目名稱:HeadlineNews,代碼行數:21,代碼來源:CacheUtils.java

示例2: drawPageHints

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private void drawPageHints(Canvas canvas) {
    if (mShowPageHints) {
        Workspace workspace = mLauncher.getWorkspace();
        int width = getMeasuredWidth();
        int page = workspace.getNextPage();
        CellLayout leftPage = (CellLayout) workspace.getChildAt(mIsRtl ? page + 1 : page - 1);
        CellLayout rightPage = (CellLayout) workspace.getChildAt(mIsRtl ? page - 1 : page + 1);

        if (leftPage != null && leftPage.isDragTarget()) {
            Drawable left = mInScrollArea && leftPage.getIsDragOverlapping() ?
                    mLeftHoverDrawableActive : mLeftHoverDrawable;
            left.setBounds(0, mScrollChildPosition.top,
                    left.getIntrinsicWidth(), mScrollChildPosition.bottom);
            left.draw(canvas);
        }
        if (rightPage != null && rightPage.isDragTarget()) {
            Drawable right = mInScrollArea && rightPage.getIsDragOverlapping() ?
                    mRightHoverDrawableActive : mRightHoverDrawable;
            right.setBounds(width - right.getIntrinsicWidth(),
                    mScrollChildPosition.top, width, mScrollChildPosition.bottom);
            right.draw(canvas);
        }
    }
}
 
開發者ID:TeamBrainStorm,項目名稱:SimpleUILauncher,代碼行數:25,代碼來源:DragLayer.java

示例3: drawOverscrollFooter

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
void drawOverscrollFooter(Canvas canvas, Drawable drawable, Rect bounds) {
    final int height = drawable.getMinimumHeight();

    canvas.save();
    canvas.clipRect(bounds);

    final int span = bounds.bottom - bounds.top;
    if (span < height) {
        bounds.bottom = bounds.top + height;
    }

    drawable.setBounds(bounds);
    drawable.draw(canvas);

    canvas.restore();
}
 
開發者ID:Shmilyz,項目名稱:Swap,代碼行數:17,代碼來源:PLA_ListView.java

示例4: drawable2Bitmap

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private static Bitmap drawable2Bitmap(Drawable drawable) {
    if (drawable == null) {
        return null;
    }
    // 取 drawable 的長寬
    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();
    // 取 drawable 的顏色格式
    Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
            : Bitmap.Config.RGB_565;
    // 建立對應 bitmap
    Bitmap bitmap = Bitmap.createBitmap(w, h, config);
    // 建立對應 bitmap 的畫布
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    // 把 drawable 內容畫到畫布中
    drawable.draw(canvas);
    return bitmap;
}
 
開發者ID:li-yu,項目名稱:FakeWeather,代碼行數:20,代碼來源:ACache.java

示例5: drawableToBitmap1

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public static Bitmap drawableToBitmap1(Drawable drawable) {
    if (drawable == null) {
        return null;
    }


    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }

    Bitmap bitmap;
    int width = Math.max(drawable.getIntrinsicWidth(), 2);
    int height = Math.max(drawable.getIntrinsicHeight(), 2);
    try {
        bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
    } catch (IllegalArgumentException e) {
        MyLg.e(TAG, "Error " + e.getMessage());
        e.printStackTrace();
        bitmap = null;
    }
    return bitmap;
}
 
開發者ID:PacktPublishing,項目名稱:Expert-Android-Programming,代碼行數:26,代碼來源:SelectableRoundedImageView.java

示例6: setRightImage

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
 * 設置右側圖片
 * @param textView
 * @param resId
 * @param padding
 */
public static void setRightImage(TextView textView, int resId, float padding) {
    if (textView != null) {
        Drawable drawable = textView.getContext().getResources().getDrawable(resId);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        textView.setCompoundDrawablePadding(DensityUtils.dip2px(textView.getContext(), padding));
        textView.setCompoundDrawables(null, null, drawable, null);
    }
}
 
開發者ID:Break369,項目名稱:MyLife,代碼行數:15,代碼來源:TextViewUtils.java

示例7: getResizedDrawable

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Nullable
private static Drawable getResizedDrawable(@NonNull Context context, @Nullable Drawable drawable,
                                           int color, boolean tint) {
    try {
        if (drawable == null) {
            LogUtil.d("drawable: null");
            return null;
        }

        if (tint) {
            drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
            drawable.mutate();
        }

        int size = context.getResources().getDimensionPixelSize(R.dimen.cafebar_icon_size);
        Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
                drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);

        return new BitmapDrawable(context.getResources(),
                Bitmap.createScaledBitmap(bitmap, size, size, true));
    } catch (Exception | OutOfMemoryError e) {
        LogUtil.e(Log.getStackTraceString(e));
        return null;
    }
}
 
開發者ID:danimahardhika,項目名稱:cafebar,代碼行數:29,代碼來源:CafeBarUtil.java

示例8: fetchDrawable

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
 * Get the Drawable from URL
 */
public Drawable fetchDrawable(Resources res, String urlString) {
    try {
        InputStream is = fetch(urlString);
        Drawable drawable = new BitmapDrawable(res, is);
        scale = getScale(drawable.getIntrinsicWidth());
        drawable.setBounds(0, 0, (int) (drawable.getIntrinsicWidth() * scale), (int) (drawable.getIntrinsicHeight() * scale));
        return drawable;
    } catch (Exception e) {
        return null;
    }
}
 
開發者ID:mzlogin,項目名稱:guanggoo-android,代碼行數:15,代碼來源:MyHtmlHttpImageGetter.java

示例9: setIcon

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public void setIcon(Drawable icon) {
    this.icon = icon;
    if (icon != null) {
        if (getMeasuredHeight() <= 0)
            measure(0, 0);
        int iconWidth = (int) (getMeasuredHeight() * 0.72);
        icon.setBounds(0, 0, iconWidth, iconWidth);
    }
    if (!isChecked())
        setChecked(false);
}
 
開發者ID:LemonAppCN,項目名稱:LemonKit4Android,代碼行數:12,代碼來源:LKTabBarItem.java

示例10: onBindViewHolder

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
protected void onBindViewHolder(final RecyclerView.ViewHolder holder, Cursor cursor) {
    if (holder instanceof CaptureViewHolder) {
        CaptureViewHolder captureViewHolder = (CaptureViewHolder) holder;
        Drawable[] drawables = captureViewHolder.mHint.getCompoundDrawables();
        TypedArray ta = holder.itemView.getContext().getTheme().obtainStyledAttributes(
                new int[]{R.attr.capture_textColor});
        int color = ta.getColor(0, 0);
        ta.recycle();

        for (int i = 0; i < drawables.length; i++) {
            Drawable drawable = drawables[i];
            if (drawable != null) {
                final Drawable.ConstantState state = drawable.getConstantState();
                if (state == null) {
                    continue;
                }

                Drawable newDrawable = state.newDrawable().mutate();
                newDrawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
                newDrawable.setBounds(drawable.getBounds());
                drawables[i] = newDrawable;
            }
        }
        captureViewHolder.mHint.setCompoundDrawables(drawables[0], drawables[1], drawables[2], drawables[3]);
    } else if (holder instanceof MediaViewHolder) {
        MediaViewHolder mediaViewHolder = (MediaViewHolder) holder;

        final Item item = Item.valueOf(cursor);
        mediaViewHolder.mMediaGrid.preBindMedia(new MediaGrid.PreBindInfo(
                getImageResize(mediaViewHolder.mMediaGrid.getContext()),
                mPlaceholder,
                mSelectionSpec.countable,
                holder
        ));
        mediaViewHolder.mMediaGrid.bindMedia(item);
        mediaViewHolder.mMediaGrid.setOnMediaGridClickListener(this);
        setCheckStatus(item, mediaViewHolder.mMediaGrid);
    }
}
 
開發者ID:sathishmscict,項目名稱:Matisse-Image-and-Video-Selector,代碼行數:41,代碼來源:AlbumMediaAdapter.java

示例11: generateIconBitmaps

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private Bitmap[] generateIconBitmaps(Drawable drawable) {
  if (drawable == null)
    return null;
  Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(bitmap);
  drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
  drawable.draw(canvas);
  return generateIconBitmaps(Bitmap.createScaledBitmap(bitmap, iconSize, iconSize, false));
}
 
開發者ID:mityung,項目名稱:XERUNG,代碼行數:10,代碼來源:MaterialEditText.java

示例12: drawableToBitmap

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
 * drawable轉bitmap
 *
 * @param drawable
 * @return
 */
private Bitmap drawableToBitmap(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        return bitmapDrawable.getBitmap();
    }
    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();
    Bitmap bitmap = Bitmap.createBitmap(w, h, Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    drawable.draw(canvas);
    return bitmap;
}
 
開發者ID:newDeepLearing,項目名稱:decoy,代碼行數:20,代碼來源:ZQRoundOvalImageView.java

示例13: drawIcon

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
protected static void drawIcon(@Nonnull final Canvas canvas,@Nonnull final Drawable icon,
        final int x, final int y, final int width, final int height) {
    canvas.translate(x, y);
    icon.setBounds(0, 0, width, height);
    icon.draw(canvas);
    canvas.translate(-x, -y);
}
 
開發者ID:sergeychilingaryan,項目名稱:AOSP-Kayboard-7.1.2,代碼行數:8,代碼來源:KeyboardView.java

示例14: getBitmapFromDrawable

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private Bitmap getBitmapFromDrawable(Drawable drawable) {
    if (drawable == null) {
        return null;
    }

    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }

    try {
        Bitmap bitmap;

        if (drawable instanceof ColorDrawable) {
            bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
        } else {
            bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);
        }

        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
        return bitmap;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
開發者ID:afiqiqmal,項目名稱:My-Android-Base-Code,代碼行數:28,代碼來源:CircleImageView.java

示例15: setDrawleft

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public void setDrawleft(TextView view, int id) {
    if (!isAdded()) return;
    Drawable drawable_n = getResources().getDrawable(id);
    drawable_n.setBounds(0, 0, drawable_n.getMinimumWidth(), drawable_n.getMinimumHeight());  //此為必須寫的
    view.setCompoundDrawables(drawable_n, null, null, null);
}
 
開發者ID:fengdongfei,項目名稱:CXJPadProject,代碼行數:7,代碼來源:OrderDetailFragment.java


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