当前位置: 首页>>代码示例>>Java>>正文


Java Shape类代码示例

本文整理汇总了Java中android.graphics.drawable.shapes.Shape的典型用法代码示例。如果您正苦于以下问题:Java Shape类的具体用法?Java Shape怎么用?Java Shape使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Shape类属于android.graphics.drawable.shapes包,在下文中一共展示了Shape类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateRoundDrawable

import android.graphics.drawable.shapes.Shape; //导入依赖的package包/类
/**
 * Generate bg drawable drawable.
 *
 * @param pressColor   the press color
 * @param defaultColor the default color
 * @return the drawable
 */
public static Drawable generateRoundDrawable(float radii, int pressColor, int defaultColor) {
    //圆角
    Shape roundRectShape = new RoundRectShape(new float[]{radii, radii, radii, radii, radii, radii, radii, radii}, null, null);//圆角背景

    //按下状态
    ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圆角shape
    shopDrawablePress.getPaint().setColor(pressColor);//设置颜色

    //正常状态
    ShapeDrawable shopDrawableNormal = new ShapeDrawable(roundRectShape);
    shopDrawableNormal.getPaint().setColor(defaultColor);

    StateListDrawable bgStateDrawable = new StateListDrawable();//状态shape
    bgStateDrawable.addState(new int[]{android.R.attr.state_pressed}, shopDrawablePress);//按下状态
    bgStateDrawable.addState(new int[]{-android.R.attr.state_enabled}, shopDrawablePress);
    bgStateDrawable.addState(new int[]{}, shopDrawableNormal);//其他状态

    return bgStateDrawable;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:27,代码来源:ResUtil.java

示例2: generateBorderDrawable

import android.graphics.drawable.shapes.Shape; //导入依赖的package包/类
/**
 * 正常 圆角边框;
 * 按下 圆角色块
 */
public static Drawable generateBorderDrawable(float radii, float borderWidth, int pressColor, int defaultColor) {

    //外环的圆角矩形
    float[] outRadii = new float[]{radii, radii, radii, radii, radii, radii, radii, radii};//四个角的 圆角幅度,8个可以设置的值,每个角都有2个边 2*4=8个
    RectF inset = new RectF(borderWidth, borderWidth, borderWidth, borderWidth);

    //按下状态
    Shape roundRectShape = new RoundRectShape(outRadii, null, null);//圆角背景
    ShapeDrawable shopDrawablePress = new ShapeDrawable(roundRectShape);//圆角shape
    shopDrawablePress.getPaint().setColor(pressColor);//设置颜色

    //正常状态
    Shape roundRectShapeNormal = new RoundRectShape(outRadii, inset, outRadii);
    ShapeDrawable shopDrawableNormal = new ShapeDrawable(roundRectShapeNormal);
    shopDrawableNormal.getPaint().setColor(defaultColor);

    StateListDrawable bgStateDrawable = new StateListDrawable();//状态shape
    bgStateDrawable.addState(new int[]{android.R.attr.state_pressed}, shopDrawablePress);//按下状态
    bgStateDrawable.addState(new int[]{}, shopDrawableNormal);//其他状态

    return bgStateDrawable;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:27,代码来源:ResUtil.java

示例3: onDraw

import android.graphics.drawable.shapes.Shape; //导入依赖的package包/类
/**
	 * #drawをOverrideしても良いけど、色々処理をしているので#onDrawの方をOverrideする
	 * (#onDrawは#drawから呼び出される)
	 */
	@Override
	protected void onDraw(final Shape shape, final Canvas canvas, final Paint paint) {
		canvas.rotate(mRotation, mPivot.x, mPivot.y);
		// これを入れると背景が透過する(backgroundの指定してても見えなくなる)
//		canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
		final int count = canvas.save();
//		final DrawFilter org = canvas.getDrawFilter();
		try {
//	        canvas.setDrawFilter(mDrawFilter);
	        mPaint.setShader(mShader);
/*	        paint.setColor(Color.TRANSPARENT);	// 消しゴムの時
	        paint.setXfermode(mClearXfermode); */
//	        canvas.drawPaint(mPaint);
	        super.onDraw(shape, canvas, paint);	// 描画自体は上位に任せる(実際はShape#drawに任せる)
		} finally {
//	        canvas.setDrawFilter(org);
			canvas.restoreToCount(count);
		}
	}
 
开发者ID:saki4510t,项目名称:libcommon,代码行数:24,代码来源:BrushDrawable.java

示例4: setRipple

import android.graphics.drawable.shapes.Shape; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void setRipple(final int mask) {
    if (SDK_LOLLIPOP) {
        if (mask != 0) {
            ShapeDrawable shape = new ShapeDrawable(new Shape() {
                @Override
                public void draw(Canvas canvas, Paint paint) {
                    paint.setColor(mask);
                    canvas.drawPath(((CustomRoundRectDrawable) drawable).buildConvexPath(), paint);
                }
            });

            RippleDrawable ripple = new RippleDrawable(buildColorStateList(mask), drawable, shape);
            view.setBackground(ripple);
        } else {
            view.setBackground(drawable);
        }
    } else {
        Log.i(TAG, "setRipple() only work for API 21+");
    }
}
 
开发者ID:mthli,项目名称:Slice,代码行数:22,代码来源:Slice.java

示例5: onDraw

import android.graphics.drawable.shapes.Shape; //导入依赖的package包/类
@Override
protected void onDraw(Shape shape, Canvas canvas, Paint paint) {
    super.onDraw(shape, canvas, paint);
    if (!TextUtils.isEmpty(text)) {

        Rect r = getBounds();
        if (dotTextSize == 0) {
            dotTextSize = (int) (r.width() * 0.5);
            textPaint.setTextSize(dotTextSize);
        }
        //保证文字居中
        Paint.FontMetricsInt fontMetrics = textPaint.getFontMetricsInt();
        int baseline = r.top + (r.bottom - r.top - fontMetrics.bottom + fontMetrics.top) / 2 - fontMetrics.top;
        textPaint.setTextAlign(Paint.Align.CENTER);
        canvas.drawText(text, r.centerX(), baseline, textPaint);
    }
}
 
开发者ID:razerdp,项目名称:FriendCircle,代码行数:18,代码来源:DotWidget.java

示例6: BorderDrawable

import android.graphics.drawable.shapes.Shape; //导入依赖的package包/类
public BorderDrawable(String shapeType, final int borderColor, final int borderWidth)
{
	super();

	final Shape shape = shapeType.equals(RECT) ? new RectShape() : new OvalShape();

	final ShapeDrawable transparentShape = new ShapeDrawable(shape);
	transparentShape.getPaint().setColor(0x00000000);// Transparent

	final GradientDrawable shapeDrawable = new GradientDrawable();
	shapeDrawable.setShape(shapeType.equals(RECT) ? GradientDrawable.RECTANGLE : GradientDrawable.OVAL);
	shapeDrawable.setStroke(borderWidth, borderColor);

	addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused, -android.R.attr.state_pressed }, shapeDrawable);
	addState(new int[] { android.R.attr.state_enabled, -android.R.attr.state_focused, android.R.attr.state_pressed }, shapeDrawable);
	addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused, android.R.attr.state_pressed }, shapeDrawable);
	addState(new int[] {}, transparentShape);
}
 
开发者ID:jonathangerbaud,项目名称:Klyph,代码行数:19,代码来源:ProfileImageView.java

示例7: set

import android.graphics.drawable.shapes.Shape; //导入依赖的package包/类
private void set(@Nullable Drawable bitmapDrawable, @Nullable Bitmap bitmap, @Nullable Shape shape, int state, int color) {
        if (bitmapDrawable != null || bitmap != null || shape != null) {
            mMode = Mode.MULTI_ICON;
        }
        mColors[state] = color;
//        mShapes[state] = shape;
        mShapeDrawables[state] = shape != null ? new ShapeDrawable(shape) : null;
        if (bitmapDrawable == null && bitmap != null) {
            mBitmapDrawables[state] = null;
            mBitmaps[state] = bitmap;
            mFinal[state] = null;
        } else if (bitmapDrawable instanceof BitmapDrawable) {
            mBitmapDrawables[state] = (BitmapDrawable) bitmapDrawable;
            mBitmaps[state] = bitmap;
            mFinal[state] = null;
        } else {
            mBitmapDrawables[state] = null;
            mBitmaps[state] = null;
            mFinal[state] = bitmapDrawable;
        }
    }
 
开发者ID:carlosefonseca,项目名称:CEFCommon,代码行数:22,代码来源:MSDrawable.java

示例8: onDraw

import android.graphics.drawable.shapes.Shape; //导入依赖的package包/类
protected void onDraw(Shape shape, Canvas canvas, Paint paint) {
    // V1
    shape.draw(canvas, fillpaint);
    shape.draw(canvas, strokepaint);

    // V2
    // shape.resize(canvas.getClipBounds().right,
    // canvas.getClipBounds().bottom);
    // shape.draw(canvas, fillpaint);
    //
    // Matrix matrix = new Matrix();
    // matrix.setRectToRect(new RectF(0, 0,
    // canvas.getClipBounds().right, canvas.getClipBounds().bottom), new
    // RectF(strokeWidth / 2, strokeWidth / 2,
    // canvas.getClipBounds().right - strokeWidth
    // / 2, canvas.getClipBounds().bottom - strokeWidth / 2),
    // Matrix.ScaleToFit.FILL);
    // canvas.concat(matrix);
    //
    // shape.draw(canvas, strokepaint);
}
 
开发者ID:gabuzomeu,项目名称:geoPingProject,代码行数:22,代码来源:PersonColorDrawableHelper.java

示例9: BubbleBackgroudShapeDrawable

import android.graphics.drawable.shapes.Shape; //导入依赖的package包/类
public BubbleBackgroudShapeDrawable(Shape s,final int fill, int stroke, int strokeWidth) {
            super(s);
            this.strokeWidth = strokeWidth;
            fillpaint =  this.getPaint();
//            fillpaint.setColor(fill);
            final Rect r = getBounds();
//            fillpaint.setShader(new LinearGradient(0, r.width(), 0, 0,  fill, Color.WHITE, Shader.TileMode.MIRROR));
            ShapeDrawable.ShaderFactory sf = new ShapeDrawable.ShaderFactory() {
                @Override
                public Shader resize(int width, int height) { 
                    LinearGradient lg =   new LinearGradient(0, width, 0, 0,  Color.WHITE,  fill, Shader.TileMode.REPEAT);
                    return lg;
                }
            };
            setShaderFactory(sf);
            strokepaint = new Paint(fillpaint);
            strokepaint.setStyle(Paint.Style.STROKE);
            strokepaint.setStrokeWidth(strokeWidth);
            strokepaint.setColor(stroke);
        }
 
开发者ID:gabuzomeu,项目名称:geoPingProject,代码行数:21,代码来源:PersonColorDrawableHelper.java

示例10: onPreDraw

import android.graphics.drawable.shapes.Shape; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
@Override
public boolean onPreDraw() {

	mContentHolder.measure(getMeasuredWidth(), getTextHeight() + mPointHeightPx);

	Shape shape = getTooltipShape();
	ShapeDrawable d = new ShapeDrawable(shape);
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
		mContentHolder.setBackground(d);
	} else {
		mContentHolder.setBackgroundDrawable(d);
	}

	return true;
}
 
开发者ID:buddycloud,项目名称:buddycloud-android,代码行数:18,代码来源:TooltipErrorView.java

示例11: onDraw

import android.graphics.drawable.shapes.Shape; //导入依赖的package包/类
@Override
protected void onDraw(Shape shape, Canvas canvas, Paint paint) {
	paint.setColor(this.fill);
	canvas.drawRect(canvas.getClipBounds(), paint);
	
	// border
	paint.setColor(this.stroke);
	
	// left border
	if (column != 0) {
		canvas.drawLine(0, 0, 0, canvas.getClipBounds().bottom, paint);
	}
	
	// right border
	//canvas.drawLine(canvas.getClipBounds().right - 1, 0, canvas.getClipBounds().right - 1, canvas.getClipBounds().bottom, paint);
	
	// top border
	if (row != 0) {
		canvas.drawLine(0, 0, canvas.getClipBounds().right, 0, paint);
	}
	
	// bottom border
	//canvas.drawLine(0, canvas.getClipBounds().bottom - 1, canvas.getClipBounds().right, canvas.getClipBounds().bottom - 1, paint);
}
 
开发者ID:edoli,项目名称:CalendarLMS,代码行数:25,代码来源:CalendarAdapter.java

示例12: BottomBorderBackground

import android.graphics.drawable.shapes.Shape; //导入依赖的package包/类
public BottomBorderBackground(Shape s, int fill, int stroke) {
    super(s);
    fillpaint = new Paint(this.getPaint());
    fillpaint.setColor(fill);
    strokepaint = new Paint(fillpaint);
    strokepaint.setStyle(Paint.Style.STROKE);
    strokepaint.setStrokeWidth(2);
    strokepaint.setColor(stroke);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:DefaultSectionAdapter.java

示例13: initOverlay

import android.graphics.drawable.shapes.Shape; //导入依赖的package包/类
private void initOverlay(Context context, Shape shape) {
    // pressed state
    TypedValue typedValue = new TypedValue();
    Theme theme = context.getTheme();

    mPressedOverlay = new ShapeDrawable(shape);
    int overlayColor = Color.parseColor("#aa888888");
    if (theme.resolveAttribute(R.attr.cp_badgeOverlayColor, typedValue, true)) {
        overlayColor = typedValue.data;
    }
    Paint paint = mPressedOverlay.getPaint();
    paint.setColor(overlayColor);
    paint.setStyle(Paint.Style.FILL);
    paint.setAntiAlias(true);
}
 
开发者ID:adithya321,项目名称:SOS-The-Healthcare-Companion,代码行数:16,代码来源:ContactBadge.java

示例14: CircleDrawable

import android.graphics.drawable.shapes.Shape; //导入依赖的package包/类
private CircleDrawable(Shape s) {
    super(s);
    circleInsetHorizontal = hasShadow() ? mShadowRadius + Math.abs(mShadowXOffset) : 0;
    circleInsetVertical = hasShadow() ? mShadowRadius + Math.abs(mShadowYOffset) : 0;

    if (mProgressBarEnabled) {
        circleInsetHorizontal += mProgressWidth;
        circleInsetVertical += mProgressWidth;
    }
}
 
开发者ID:WeiMei-Tian,项目名称:editor-sql,代码行数:11,代码来源:FloatingActionButton.java

示例15: onDraw

import android.graphics.drawable.shapes.Shape; //导入依赖的package包/类
@Override
protected void onDraw(Shape shape, Canvas canvas, Paint paint) {
    float offset = mStrokeWidth / 2;
    while (offset < shape.getHeight()) {
        canvas.drawLine(0, offset, shape.getWidth(), offset, mStrokePaint);
        offset += mStrokeOffset;
    }
}
 
开发者ID:hh-in-zhuzhou,项目名称:ShangHanLun,代码行数:9,代码来源:ATableViewPlainFooterDrawable.java


注:本文中的android.graphics.drawable.shapes.Shape类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。