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


Java ShapeDrawable類代碼示例

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


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

示例1: drawable

import android.graphics.drawable.ShapeDrawable; //導入依賴的package包/類
public static Drawable drawable(final int[] colorBoxes, final float[] position, final GradientAngle gradientAngle) {
    ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            AngleCoordinate ac = AngleCoordinate.getAngleCoordinate(gradientAngle, width, height);
            LinearGradient linearGradient = new LinearGradient(ac.x1, ac.y1, ac.x2, ac.y2,
                    colorBoxes,
                    position,
                    Shader.TileMode.REPEAT);
            return linearGradient;
        }
    };
    PaintDrawable paint = new PaintDrawable();
    paint.setShape(new RectShape());
    paint.setShaderFactory(shaderFactory);
    return paint;
}
 
開發者ID:akshay2211,項目名稱:Ariana,代碼行數:18,代碼來源:Ariana.java

示例2: roundBitmap

import android.graphics.drawable.ShapeDrawable; //導入依賴的package包/類
public static Bitmap roundBitmap(Bitmap bitmap, int i, int i2, float f, float f2, float f3,
                                 float f4) throws Throwable {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Rect rect = new Rect(0, 0, width, height);
    Bitmap createBitmap = (width == i && height == i2) ? Bitmap.createBitmap(bitmap.getWidth
            (), bitmap.getHeight(), Config.ARGB_8888) : Bitmap.createBitmap(i, i2, Config
            .ARGB_8888);
    Canvas canvas = new Canvas(createBitmap);
    Paint paint = new Paint();
    Rect rect2 = new Rect(0, 0, i, i2);
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(-12434878);
    float[] fArr = new float[]{f, f, f2, f2, f3, f3, f4, f4};
    ShapeDrawable shapeDrawable = new ShapeDrawable(new RoundRectShape(fArr, new RectF(0.0f,
            0.0f, 0.0f, 0.0f), fArr));
    shapeDrawable.setBounds(rect2);
    shapeDrawable.draw(canvas);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect2, paint);
    return createBitmap;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:24,代碼來源:BitmapHelper.java

示例3: select

import android.graphics.drawable.ShapeDrawable; //導入依賴的package包/類
public void select(int dayOfOrder) {
    this.selected = dayOfOrder;
    resetSelect();
    if (this.mSelectListener != null) {
        this.mSelectListener.onSelect(dayOfOrder);
    }
    TextView tv = (TextView) this.tvList.get(dayOfOrder);
    tv.setTextColor(getResources().getColor(R.color.ju));
    ShapeDrawable oval = new ShapeDrawable(new OvalShape());
    if (dayOfOrder == this.orderOfToday) {
        oval.getPaint().setColor(getResources().getColor(R.color.he));
    } else {
        oval.getPaint().setColor(getResources().getColor(R.color.hb));
    }
    tv.setBackgroundDrawable(oval);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:17,代碼來源:WeekView.java

示例4: getCornerDrawable

import android.graphics.drawable.ShapeDrawable; //導入依賴的package包/類
public static Drawable getCornerDrawable(float topLeft,
                                         float topRight,
                                         float bottomLeft,
                                         float bottomRight,
                                          @ColorInt int color) {

    float[] outerR = new float[8];
    outerR[0] = topLeft;
    outerR[1] = topLeft;
    outerR[2] = topRight;
    outerR[3] = topRight;
    outerR[4] = bottomRight;
    outerR[5] = bottomRight;
    outerR[6] = bottomLeft;
    outerR[7] = bottomLeft;

    ShapeDrawable drawable = new ShapeDrawable();
    drawable.setShape(new RoundRectShape(outerR, null, null));
    drawable.getPaint().setColor(color);

    return drawable;
}
 
開發者ID:apg-mobile,項目名稱:android-round-textview,代碼行數:23,代碼來源:DrawableHelper.java

示例5: addArrowView

import android.graphics.drawable.ShapeDrawable; //導入依賴的package包/類
/**
 * Adds an arrow view pointing at the original icon.
 * @param horizontalOffset the horizontal offset of the arrow, so that it
 *                              points at the center of the original icon
 */
private View addArrowView(int horizontalOffset, int verticalOffset, int width, int height) {
    LinearLayout.LayoutParams layoutParams = new LayoutParams(width, height);
    if (mIsLeftAligned) {
        layoutParams.gravity = Gravity.LEFT;
        layoutParams.leftMargin = horizontalOffset;
    } else {
        layoutParams.gravity = Gravity.RIGHT;
        layoutParams.rightMargin = horizontalOffset;
    }
    if (mIsAboveIcon) {
        layoutParams.topMargin = verticalOffset;
    } else {
        layoutParams.bottomMargin = verticalOffset;
    }

    View arrowView = new View(getContext());
    ShapeDrawable arrowDrawable = new ShapeDrawable(TriangleShape.create(
            width, height, !mIsAboveIcon));
    arrowDrawable.getPaint().setColor(Color.WHITE);
    arrowView.setBackground(arrowDrawable);
    arrowView.setElevation(getElevation());
    addView(arrowView, mIsAboveIcon ? getChildCount() : 0, layoutParams);
    return arrowView;
}
 
開發者ID:TeamBrainStorm,項目名稱:SimpleUILauncher,代碼行數:30,代碼來源:DeepShortcutsContainer.java

示例6: addArrowView

import android.graphics.drawable.ShapeDrawable; //導入依賴的package包/類
/**
 * Adds an arrow view pointing at the original icon.
 * @param horizontalOffset the horizontal offset of the arrow, so that it
 *                              points at the center of the original icon
 */
private View addArrowView(int horizontalOffset, int verticalOffset, int width, int height) {
    LayoutParams layoutParams = new LayoutParams(width, height);
    if (mIsLeftAligned) {
        layoutParams.gravity = Gravity.START;
        layoutParams.leftMargin = horizontalOffset;
    } else {
        layoutParams.gravity = Gravity.END;
        layoutParams.rightMargin = horizontalOffset;
    }
    if (mIsAboveIcon) {
        layoutParams.topMargin = verticalOffset;
    } else {
        layoutParams.bottomMargin = verticalOffset;
    }

    View arrowView = new View(getContext());
    if (Gravity.isVertical(((FrameLayout.LayoutParams) getLayoutParams()).gravity)) {
        // This is only true if there wasn't room for the container next to the icon,
        // so we centered it instead. In that case we don't want to show the arrow.
        arrowView.setVisibility(INVISIBLE);
    } else {
        ShapeDrawable arrowDrawable = new ShapeDrawable(TriangleShape.create(
                width, height, !mIsAboveIcon));
        Paint arrowPaint = arrowDrawable.getPaint();
        // Note that we have to use getChildAt() instead of getItemViewAt(),
        // since the latter expects the arrow which hasn't been added yet.
        PopupItemView itemAttachedToArrow = (PopupItemView)
                (getChildAt(mIsAboveIcon ? getChildCount() - 1 : 0));
        arrowPaint.setColor(itemAttachedToArrow.getArrowColor(mIsAboveIcon));
        // The corner path effect won't be reflected in the shadow, but shouldn't be noticeable.
        int radius = getResources().getDimensionPixelSize(R.dimen.popup_arrow_corner_radius);
        arrowPaint.setPathEffect(new CornerPathEffect(radius));
        arrowView.setBackground(arrowDrawable);
        arrowView.setElevation(getElevation());
    }
    addView(arrowView, mIsAboveIcon ? getChildCount() : 0, layoutParams);
    return arrowView;
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:44,代碼來源:PopupContainerWithArrow.java

示例7: createItemSeparatorBg

import android.graphics.drawable.ShapeDrawable; //導入依賴的package包/類
/**
 * 動態創建帶上分隔線或下分隔線的Drawable
 *
 * @param separatorColor
 * @param bgColor
 * @param top
 * @return
 */
public static LayerDrawable createItemSeparatorBg(@ColorInt int separatorColor, @ColorInt int bgColor, int separatorHeight, boolean top) {

    ShapeDrawable separator = new ShapeDrawable();
    separator.getPaint().setStyle(Paint.Style.FILL);
    separator.getPaint().setColor(separatorColor);

    ShapeDrawable bg = new ShapeDrawable();
    bg.getPaint().setStyle(Paint.Style.FILL);
    bg.getPaint().setColor(bgColor);

    Drawable[] layers = {separator, bg};
    LayerDrawable layerDrawable = new LayerDrawable(layers);

    layerDrawable.setLayerInset(1, 0, top ? separatorHeight : 0, 0, top ? 0 : separatorHeight);
    return layerDrawable;
}
 
開發者ID:coopese,項目名稱:qmui,代碼行數:25,代碼來源:QMUIDrawableHelper.java

示例8: createRectDrawable

import android.graphics.drawable.ShapeDrawable; //導入依賴的package包/類
private Drawable createRectDrawable(int color) {
    RoundRectShape shape = new RoundRectShape(
            new float[]{
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius,
                    mCornerRadius
            },
            null,
            null);
    ShapeDrawable shapeDrawable = new ShapeDrawable(shape);
    shapeDrawable.getPaint().setColor(color);
    return shapeDrawable;
}
 
開發者ID:WeiMei-Tian,項目名稱:editor-sql,代碼行數:19,代碼來源:Label.java

示例9: setDrawableColor

import android.graphics.drawable.ShapeDrawable; //導入依賴的package包/類
/**
 * Sets the background color of the drawable
 **/
public static void setDrawableColor(Context context, Drawable drawable, @AttrRes int colorAttrRes) {
    int colorRes = getResourceId(context, colorAttrRes);
    int color = ContextCompat.getColor(context, colorRes);
    if (drawable instanceof ShapeDrawable) {
        ((ShapeDrawable) drawable).getPaint().setColor(color);
    } else if (drawable instanceof GradientDrawable) {
        ((GradientDrawable) drawable).setColor(color);
    } else if (drawable instanceof ColorDrawable) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            ((ColorDrawable) drawable).setColor(color);
        }
    } else if (drawable instanceof RotateDrawable) {
        setDrawableColor(context, ((RotateDrawable) drawable).getDrawable(), colorAttrRes);
    }
}
 
開發者ID:kaliturin,項目名稱:BlackList,代碼行數:19,代碼來源:Utils.java

示例10: createProductImageDrawable

import android.graphics.drawable.ShapeDrawable; //導入依賴的package包/類
private Drawable createProductImageDrawable(Product product) {
    final ShapeDrawable background = new ShapeDrawable();
    background.setShape(new OvalShape());
    background.getPaint().setColor(ContextCompat.getColor(getContext(), product.color));

    final BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(),
            BitmapFactory.decodeResource(getResources(), product.image));

    final LayerDrawable layerDrawable = new LayerDrawable
            (new Drawable[]{background, bitmapDrawable});

    final int padding = (int) getResources().getDimension(R.dimen.spacing_huge);
    layerDrawable.setLayerInset(1, padding, padding, padding, padding);

    return layerDrawable;
}
 
開發者ID:Pingsh,項目名稱:Mix,代碼行數:17,代碼來源:OrderDialogFragment.java

示例11: createShadowShapeDrawable

import android.graphics.drawable.ShapeDrawable; //導入依賴的package包/類
@Override
public Drawable createShadowShapeDrawable(Context context, final CircleLoadingView circleLoadingView, int shadowColor) {
    final float density = context.getResources().getDisplayMetrics().density;
    ShapeDrawable circle = new ShapeDrawable(new OvalShape());
    circle.getPaint().setColor(shadowColor);
    final float elevation = SHADOW_ELEVATION * density;
    circleLoadingView.setElevation(elevation);

    circleLoadingView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            ViewParent p = circleLoadingView.getParent();
            if(p instanceof ViewGroup) {
                final int margin = (int) elevation;
                ViewGroup.LayoutParams params = circleLoadingView.getLayoutParams();
                if(params instanceof ViewGroup.MarginLayoutParams){
                    ((ViewGroup.MarginLayoutParams) params).setMargins(margin, margin, margin, margin);
                }
            }

            circleLoadingView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
        }
    });

    return circle;
}
 
開發者ID:lliuguangbo,項目名稱:circleloadingview,代碼行數:27,代碼來源:CircleLoadingView.java

示例12: createItemSeparatorBg

import android.graphics.drawable.ShapeDrawable; //導入依賴的package包/類
/**
 * 動態創建帶上分隔線或下分隔線的Drawable。
 *
 * @param separatorColor 分割線顏色。
 * @param bgColor        Drawable 的背景色。
 * @param top            true 則分割線為上分割線,false 則為下分割線。
 * @return 返回所創建的 Drawable。
 */
public static LayerDrawable createItemSeparatorBg(@ColorInt int separatorColor, @ColorInt int bgColor, int separatorHeight, boolean top) {

    ShapeDrawable separator = new ShapeDrawable();
    separator.getPaint().setStyle(Paint.Style.FILL);
    separator.getPaint().setColor(separatorColor);

    ShapeDrawable bg = new ShapeDrawable();
    bg.getPaint().setStyle(Paint.Style.FILL);
    bg.getPaint().setColor(bgColor);

    Drawable[] layers = {separator, bg};
    LayerDrawable layerDrawable = new LayerDrawable(layers);

    layerDrawable.setLayerInset(1, 0, top ? separatorHeight : 0, 0, top ? 0 : separatorHeight);
    return layerDrawable;
}
 
開發者ID:QMUI,項目名稱:QMUI_Android,代碼行數:25,代碼來源:QMUIDrawableHelper.java

示例13: MagnifierView

import android.graphics.drawable.ShapeDrawable; //導入依賴的package包/類
public MagnifierView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        bitmap = ((BitmapDrawable) getResources().getDrawable(R.drawable.pic)).getBitmap();
        scaledBitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth() * FACTOR, bitmap.getHeight() * FACTOR,
                true);
//        bitmap.recycle();
        mBitmapShader = new BitmapShader(scaledBitmap,
                Shader.TileMode.CLAMP,
                Shader.TileMode.CLAMP);
        mShapeDrawable = new ShapeDrawable(new OvalShape());
        mShapeDrawable.setBounds(0, 0, WIDTH, WIDTH);
        mShapeDrawable.getPaint().setShader(mBitmapShader);
        mMatrix = new Matrix();
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setColor(Color.RED);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(3);
    }
 
開發者ID:halohoop,項目名稱:AndroidDigIn,代碼行數:19,代碼來源:MagnifierView.java

示例14: setCornerRadius

import android.graphics.drawable.ShapeDrawable; //導入依賴的package包/類
void setCornerRadius(View view, int radius, int color) {
    radius = _DP(radius);
    int borderWidth = 0;// 加邊框後會出現空心圓角矩形的效果,所以設置為0
    float[] outerRadius = new float[8];
    float[] innerRadius = new float[8];
    for (int i = 0; i < 8; i++) {
        outerRadius[i] = radius + borderWidth;
        innerRadius[i] = radius;
    }
    ShapeDrawable shapeDrawable = // 創建圖形drawable
            new ShapeDrawable(
                    // 創建圓角矩形
                    new RoundRectShape(outerRadius,
                            new RectF(borderWidth, borderWidth, borderWidth, borderWidth),
                            innerRadius));
    shapeDrawable.getPaint().setColor(color);// 使用指定的顏色繪製,即背景顏色
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        // 高版本SDK使用新的API
        view.setBackground(shapeDrawable);
    } else {
        view.setBackgroundDrawable(shapeDrawable);
    }
}
 
開發者ID:LemonAppCN,項目名稱:LemonHello4Android,代碼行數:24,代碼來源:LemonHelloPrivateAnimationTool.java

示例15: onBindViewHolder

import android.graphics.drawable.ShapeDrawable; //導入依賴的package包/類
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
    RestTest restTest = datas.get(position);
    RoundRectShape shape = new RoundRectShape(new float[]{8, 8, 8, 8, 8, 8, 8, 8}, null, null);
    ShapeDrawable drawable = new ShapeDrawable(shape);

    String color = "6bbd5b";
    switch (restTest.getMethod().toUpperCase()) {
        case "GET":
            break;
        case "POST":
            color = "248fb2";
            break;
        case "DELETE":
            color = "e27a7a";
            break;
        case "PUT":
            color = "9b708b";
            break;
    }
    drawable.getPaint().setColor(Color.parseColor("#" + color));
    holder.tv.setBackground(drawable);
    holder.tv.setText(restTest.getMethod().toUpperCase());

    holder.spec.setText(restTest.getUrl());
}
 
開發者ID:Sayi,項目名稱:RestClient,代碼行數:27,代碼來源:RestTestAdapter.java


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