当前位置: 首页>>代码示例>>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;未经允许,请勿转载。