本文整理匯總了Java中android.graphics.drawable.GradientDrawable.setGradientRadius方法的典型用法代碼示例。如果您正苦於以下問題:Java GradientDrawable.setGradientRadius方法的具體用法?Java GradientDrawable.setGradientRadius怎麽用?Java GradientDrawable.setGradientRadius使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.drawable.GradientDrawable
的用法示例。
在下文中一共展示了GradientDrawable.setGradientRadius方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createCircleGradientDrawable
import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
/**
* 創建一張漸變圖片,支持圓角
*
* @param startColor 漸變開始色
* @param endColor 漸變結束色
* @param radius 圓角大小
* @param centerX 漸變中心點 X 軸坐標
* @param centerY 漸變中心點 Y 軸坐標
* @return
*/
@TargetApi(16)
public static GradientDrawable createCircleGradientDrawable(@ColorInt int startColor,
@ColorInt int endColor, int radius,
@FloatRange(from = 0f, to = 1f) float centerX,
@FloatRange(from = 0f, to = 1f) float centerY) {
GradientDrawable gradientDrawable = new GradientDrawable();
gradientDrawable.setColors(new int[]{
startColor,
endColor
});
gradientDrawable.setGradientType(GradientDrawable.RADIAL_GRADIENT);
gradientDrawable.setGradientRadius(radius);
gradientDrawable.setGradientCenter(centerX, centerY);
return gradientDrawable;
}
示例2: createCircleGradientDrawable
import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
/**
* 創建一張漸變圖片,支持韻腳。
*
* @param startColor 漸變開始色
* @param endColor 漸變結束色
* @param radius 圓角大小
* @param centerX 漸變中心點 X 軸坐標
* @param centerY 漸變中心點 Y 軸坐標
* @return 返回所創建的漸變圖片。
*/
@TargetApi(16)
public static GradientDrawable createCircleGradientDrawable(@ColorInt int startColor,
@ColorInt int endColor, int radius,
@FloatRange(from = 0f, to = 1f) float centerX,
@FloatRange(from = 0f, to = 1f) float centerY) {
GradientDrawable gradientDrawable = new GradientDrawable();
gradientDrawable.setColors(new int[]{
startColor,
endColor
});
gradientDrawable.setGradientType(GradientDrawable.RADIAL_GRADIENT);
gradientDrawable.setGradientRadius(radius);
gradientDrawable.setGradientCenter(centerX, centerY);
return gradientDrawable;
}
示例3: initBackground
import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
private void initBackground() {
GradientDrawable.Orientation orientation = getOrientation();
GradientDrawable drawable = new GradientDrawable(orientation, new int[]{bgGradientStart, bgGradientCenter, bgGradientEnd});
drawable.setShape(GradientDrawable.RECTANGLE);
drawable.setCornerRadius(dialogRadius);
switch (bgGradientType) {
case GRADIENT_RADIAL:
drawable.setGradientType(GradientDrawable.RADIAL_GRADIENT);
break;
case GRADIENT_SWEEP:
drawable.setGradientType(GradientDrawable.SWEEP_GRADIENT);
break;
default:
drawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
break;
}
if (isHalloween) {
drawable.setGradientType(GradientDrawable.RADIAL_GRADIENT);
drawable.setGradientRadius(getContext().getResources().getDimensionPixelSize(R.dimen.dialog_height) / 2);
} else {
drawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
root.setBackground(drawable);
} else {
root.setBackgroundDrawable(drawable);
}
}
示例4: setGradientRadius
import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
void setGradientRadius(Context context, AttributeSet attrs, GradientDrawable drawable, int gradientType) throws XmlPullParserException {
TypedArray a = obtainAttributes(context.getResources(), context.getTheme(), attrs, new int[]{android.R.attr.gradientRadius});
TypedValue value = a.peekValue(0);
if (value != null) {
boolean radiusRel = value.type == TypedValue.TYPE_FRACTION;
drawable.setGradientRadius(radiusRel ? value.getFraction(1.0f, 1.0f) : value.getFloat());
} else if (gradientType == GradientDrawable.RADIAL_GRADIENT) {
throw new XmlPullParserException(
"<gradient> tag requires 'gradientRadius' "
+ "attribute with radial type");
}
a.recycle();
}
示例5: drawBackground
import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
private void drawBackground(View v, int color, boolean isCircle) {
if (isCircle) {
GradientDrawable gd = new GradientDrawable();
gd.setGradientType(GradientDrawable.RADIAL_GRADIENT);
gd.setColors(new int[]{color, Color.TRANSPARENT });
gd.setGradientRadius((Defaults.IMAGE_HEIGHT - Defaults.CIRCLE_PADDING)/2);
v.setBackground(gd);
} else {
ShapeDrawable oval = new ShapeDrawable (new OvalShape());
oval.getPaint().setColor(color);
v.setBackground(oval);
}
}
示例6: create
import android.graphics.drawable.GradientDrawable; //導入方法依賴的package包/類
public static GradientDrawable create(@ColorInt int startColor, @ColorInt int endColor, int radius,
@FloatRange(from = 0f, to = 1f) float centerX,
@FloatRange(from = 0f, to = 1f) float centerY) {
GradientDrawable gradientDrawable = new GradientDrawable();
gradientDrawable.setColors(new int[]{
startColor,
endColor
});
gradientDrawable.setGradientType(GradientDrawable.RADIAL_GRADIENT);
gradientDrawable.setGradientRadius(radius);
gradientDrawable.setGradientCenter(centerX, centerY);
return gradientDrawable;
}