當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。