本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
}
示例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());
}