本文整理汇总了Java中android.graphics.drawable.GradientDrawable.RECTANGLE属性的典型用法代码示例。如果您正苦于以下问题:Java GradientDrawable.RECTANGLE属性的具体用法?Java GradientDrawable.RECTANGLE怎么用?Java GradientDrawable.RECTANGLE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.graphics.drawable.GradientDrawable
的用法示例。
在下文中一共展示了GradientDrawable.RECTANGLE属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ShapeSelector
private ShapeSelector() {
//initialize default values
mShape = GradientDrawable.RECTANGLE;
mDefaultBgColor = Color.TRANSPARENT;
mDisabledBgColor = Color.TRANSPARENT;
mPressedBgColor = Color.TRANSPARENT;
mSelectedBgColor = Color.TRANSPARENT;
mFocusedBgColor = Color.TRANSPARENT;
mStrokeWidth = 0;
mDefaultStrokeColor = Color.TRANSPARENT;
mDisabledStrokeColor = Color.TRANSPARENT;
mPressedStrokeColor = Color.TRANSPARENT;
mSelectedStrokeColor = Color.TRANSPARENT;
mFocusedStrokeColor = Color.TRANSPARENT;
mCornerRadius = 0;
}
示例2: Builder
public Builder(Context context, String text) {
this.context = context;
this.text = text;
shape = GradientDrawable.RECTANGLE;
backCol = Color.WHITE;
borderCol = Color.BLACK;
textCol = Color.BLACK;
imageRes = 0;
}
示例3: initView
private void initView(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundLatout);
//显示类型
int shapeTpe = a.getInt(R.styleable.RoundLatout_viewShapeTpe, shapeTypes[0]);
//圆角大小
float cornerRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewCornerRadius, 0);
float topLeftRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewTopLeftRadius, 0);
float topRightRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewTopRightRadius, 0);
float bottomLeftRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewBottomLeftRadius, 0);
float bottomRightRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewBottomRightRadius, 0);
//填充色
int solidColor = a.getColor(R.styleable.RoundLatout_viewSolidColor, 0x0);
//边框
int strokeColor = a.getColor(R.styleable.RoundLatout_viewStrokeColor, 0x0);
int strokeWidth = a.getDimensionPixelSize(R.styleable.RoundLatout_viewStrokeWidth, 0);
int strokeDashWidth = a.getDimensionPixelSize(R.styleable.RoundLatout_viewStrokeDashWidth, 0);
int strokeDashGap = a.getDimensionPixelSize(R.styleable.RoundLatout_viewStrokeDashGap, 0);
a.recycle();
GradientDrawable gd = new GradientDrawable();
gd.setColor(solidColor);
//设置类型
gd.setShape(shapeTypes[shapeTpe]);
//类型为矩形才可设置圆角
if (shapeTypes[shapeTpe] == GradientDrawable.RECTANGLE) {
if (cornerRadius != 0) {
gd.setCornerRadius(cornerRadius);
} else {
gd.setCornerRadii(new float[]{topLeftRadius, topLeftRadius, topRightRadius, topRightRadius, bottomRightRadius, bottomRightRadius, bottomLeftRadius, bottomLeftRadius});
}
}
gd.setStroke(strokeWidth, strokeColor, strokeDashWidth, strokeDashGap);
setBackground(gd);
}
示例4: initView
private void initView(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundLatout);
//显示类型
int shapeTpe = a.getInt(R.styleable.RoundLatout_viewShapeTpe, shapeTypes[0]);
//圆角大小
float cornerRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewCornerRadius, 0);
float topLeftRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewTopLeftRadius, 0);
float topRightRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewTopRightRadius, 0);
float bottomLeftRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewBottomLeftRadius, 0);
float bottomRightRadius = a.getLayoutDimension(R.styleable.RoundLatout_viewBottomRightRadius, 0);
//填充色
int solidColor = a.getColor(R.styleable.RoundLatout_viewSolidColor, 0x0);
//边框
int strokeColor = a.getColor(R.styleable.RoundLatout_viewStrokeColor, 0x0);
int strokeWidth = a.getDimensionPixelSize(R.styleable.RoundLatout_viewStrokeWidth, 0);
int strokeDashWidth = a.getDimensionPixelSize(R.styleable.RoundLatout_viewStrokeDashWidth, 0);
int strokeDashGap = a.getDimensionPixelSize(R.styleable.RoundLatout_viewStrokeDashGap, 0);
a.recycle();
GradientDrawable gd = new GradientDrawable();
gd.setColor(solidColor);
//设置类型
gd.setShape(shapeTypes[shapeTpe]);
//类型为矩形才可设置圆角
if (shapeTypes[shapeTpe] == GradientDrawable.RECTANGLE) {
if (cornerRadius != 0) {
gd.setCornerRadius(cornerRadius);
} else {
gd.setCornerRadii(new float[]{topLeftRadius, topLeftRadius, topRightRadius, topRightRadius, bottomRightRadius, bottomRightRadius, bottomLeftRadius, bottomLeftRadius});
}
}
gd.setStroke(strokeWidth, strokeColor, strokeDashWidth, strokeDashGap);
setBackground(gd);
}