本文整理匯總了Java中android.graphics.drawable.LayerDrawable.setLayerInset方法的典型用法代碼示例。如果您正苦於以下問題:Java LayerDrawable.setLayerInset方法的具體用法?Java LayerDrawable.setLayerInset怎麽用?Java LayerDrawable.setLayerInset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.drawable.LayerDrawable
的用法示例。
在下文中一共展示了LayerDrawable.setLayerInset方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: create
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
public Drawable create(Context context) {
final GradientDrawable bubble = new GradientDrawable();
final int radius = context.getResources().getDimensionPixelSize(R.dimen.message_bubble_corner_radius);
final float[] radii = cornerBooleansToRadii(corners, radius);
bubble.setColor(color);
bubble.setCornerRadii(radii);
if (!hasShadow) {
return bubble;
} else {
final GradientDrawable shadow = new GradientDrawable();
final int distance = context.getResources().getDimensionPixelSize(R.dimen.message_bubble_shadow_distance);
shadow.setColor(shadowColor);
shadow.setCornerRadii(radii);
final LayerDrawable layers = new LayerDrawable(new Drawable[]{shadow, bubble});
layers.setLayerInset(1, 0, 0, 0, distance);
return layers;
}
}
示例2: createCircleDrawable
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
private Drawable createCircleDrawable(int color, float strokeWidth) {
int alpha = Color.alpha(color);
int opaqueColor = opaque(color);
ShapeDrawable fillDrawable = new ShapeDrawable(new OvalShape());
final Paint paint = fillDrawable.getPaint();
paint.setAntiAlias(true);
paint.setColor(opaqueColor);
Drawable[] layers = {
fillDrawable,
createInnerStrokesDrawable(opaqueColor, strokeWidth)
};
LayerDrawable drawable = alpha == 255 || !mStrokeVisible
? new LayerDrawable(layers)
: new TranslucentLayerDrawable(alpha, layers);
int halfStrokeWidth = (int) (strokeWidth / 2f);
drawable.setLayerInset(1, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth);
return drawable;
}
示例3: createItemSeparatorBg
import android.graphics.drawable.LayerDrawable; //導入方法依賴的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;
}
示例4: createProductImageDrawable
import android.graphics.drawable.LayerDrawable; //導入方法依賴的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;
}
示例5: getCircleIcon
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
private static Bitmap getCircleIcon(
Context context, @ColorInt int backgroundColor, int backgroundInset,
@DrawableRes int iconResId, @ColorInt int iconColor, int iconInset) {
Drawable[] layers = new Drawable[2];
ShapeDrawable background = new ShapeDrawable(new OvalShape());
background.getPaint().setColor(backgroundColor);
Drawable icon = ContextCompat.getDrawable(context, iconResId);
Drawable tintedIcon = DrawableCompat.wrap(icon.mutate());
DrawableCompat.setTint(tintedIcon, iconColor);
layers[0] = background;
layers[1] = tintedIcon;
LayerDrawable layerDrawable = new LayerDrawable(layers);
layerDrawable.setLayerInset(1, iconInset, iconInset, iconInset, iconInset);
layerDrawable.setLayerInset(0, backgroundInset, backgroundInset, backgroundInset, backgroundInset);
return drawableToBitmap(layerDrawable);
}
示例6: createProductImageDrawable
import android.graphics.drawable.LayerDrawable; //導入方法依賴的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;
}
示例7: showAtLocation
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
public void showAtLocation(final View v, int x, int y) {
final PopupMenu that = this;
this.window.setOnDismissListener(new PopupWindow.OnDismissListener() {
public void onDismiss() {
that.main_layout.removeAllViews();
}
});
this.main_layout = new LinearLayout(this.ctx);
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { (NinePatchDrawable)this.ctx.getResources().getDrawable(android.R.drawable.dialog_frame), new ColorDrawable(Color.WHITE) });
layerDrawable.setLayerInset(0, Utils.dip2px(this.ctx, 5), Utils.dip2px(this.ctx, 5) + 3, Utils.dip2px(this.ctx, 5), Utils.dip2px(this.ctx, 5));
this.main_layout.setBackgroundDrawable(layerDrawable);
this.main_layout.addView(this.contentViewLayout);
this.window.setContentView(this.main_layout);
this.window.setWidth(this.width);
this.window.setHeight(this.height);
this.window.showAsDropDown(v, x, y);
}
示例8: createItemSeparatorBg
import android.graphics.drawable.LayerDrawable; //導入方法依賴的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;
}
示例9: updateBackground
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
void updateBackground() {
final float strokeWidth = getDimension(R.dimen.fab_stroke_width);
final float halfStrokeWidth = strokeWidth / 2f;
LayerDrawable layerDrawable = new LayerDrawable(
new Drawable[] {
getResources().getDrawable(mSize == SIZE_NORMAL ? R.drawable.fab_bg_normal : R.drawable.fab_bg_mini),
createFillDrawable(strokeWidth),
createOuterStrokeDrawable(strokeWidth),
getIconDrawable()
});
int iconOffset = (int) (mCircleSize - getDimension(R.dimen.fab_icon_size)) / 2;
int circleInsetHorizontal = (int) (mShadowRadius);
int circleInsetTop = (int) (mShadowRadius - mShadowOffset);
int circleInsetBottom = (int) (mShadowRadius + mShadowOffset);
layerDrawable.setLayerInset(1,
circleInsetHorizontal,
circleInsetTop,
circleInsetHorizontal,
circleInsetBottom);
layerDrawable.setLayerInset(2,
(int) (circleInsetHorizontal - halfStrokeWidth),
(int) (circleInsetTop - halfStrokeWidth),
(int) (circleInsetHorizontal - halfStrokeWidth),
(int) (circleInsetBottom - halfStrokeWidth));
layerDrawable.setLayerInset(3,
circleInsetHorizontal + iconOffset,
circleInsetTop + iconOffset,
circleInsetHorizontal + iconOffset,
circleInsetBottom + iconOffset);
setBackgroundCompat(layerDrawable);
}
示例10: updateBackground
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
void updateBackground() {
final float strokeWidth = getDimension(R.dimen.fab_stroke_width);
final float halfStrokeWidth = strokeWidth / 2f;
LayerDrawable layerDrawable = new LayerDrawable(
new Drawable[]{
getResources().getDrawable(mSize == SIZE_NORMAL ? R.mipmap.fab_bg_normal : R.mipmap.fab_bg_mini),
createFillDrawable(strokeWidth),
createOuterStrokeDrawable(strokeWidth),
getIconDrawable()
});
int iconOffset = (int) (mCircleSize - getDimension(R.dimen.fab_icon_size)) / 2;
int circleInsetHorizontal = (int) (mShadowRadius);
int circleInsetTop = (int) (mShadowRadius - mShadowOffset);
int circleInsetBottom = (int) (mShadowRadius + mShadowOffset);
layerDrawable.setLayerInset(1,
circleInsetHorizontal,
circleInsetTop,
circleInsetHorizontal,
circleInsetBottom);
layerDrawable.setLayerInset(2,
(int) (circleInsetHorizontal - halfStrokeWidth),
(int) (circleInsetTop - halfStrokeWidth),
(int) (circleInsetHorizontal - halfStrokeWidth),
(int) (circleInsetBottom - halfStrokeWidth));
layerDrawable.setLayerInset(3,
circleInsetHorizontal + iconOffset,
circleInsetTop + iconOffset,
circleInsetHorizontal + iconOffset,
circleInsetBottom + iconOffset);
setBackgroundCompat(layerDrawable);
}
示例11: MenuItem
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
public MenuItem(Context _ctx) {
this.ctx = _ctx;
this.iconView = new TextView(this.ctx);
this.articleView = new TextView(this.ctx);
this.iconView.setLayoutParams(new LinearLayout.LayoutParams(Utils.dip2px(this.ctx, 25), -1));
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { Utils.ColorFilter((BitmapDrawable) this.ctx.getResources().getDrawable(R.drawable.ic_menu_right), MyColor.BLUE.getColor()) });
layerDrawable.setLayerInset(0, Utils.dip2px(this.ctx, 3), Utils.dip2px(this.ctx, 3), Utils.dip2px(this.ctx, 3), Utils.dip2px(this.ctx, 3));
this.iconView.setBackgroundDrawable(layerDrawable);
}
示例12: makeClusterBackground
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
private LayerDrawable makeClusterBackground() {
mColoredCircleBackground = new ShapeDrawable(new OvalShape());
ShapeDrawable outline = new ShapeDrawable(new OvalShape());
outline.getPaint().setColor(0x80ffffff); // Transparent white.
LayerDrawable background = new LayerDrawable(new Drawable[] {outline, mColoredCircleBackground});
int strokeWidth = (int) (mDensity * 3);
background.setLayerInset(1, strokeWidth, strokeWidth, strokeWidth, strokeWidth);
return background;
}
示例13: makeClusterBackground
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
private LayerDrawable makeClusterBackground() {
mColoredCircleBackground = new ShapeDrawable(new OvalShape());
ShapeDrawable outline = new ShapeDrawable(new OvalShape());
outline.getPaint().setColor(0x80ffffff); // Transparent white.透明白色
//通過以下設置,將底圖多出來的顯示 取消掉
outline.getPaint().setAlpha(0);
outline.getPaint().setStrokeMiter(0.01f);
LayerDrawable background = new LayerDrawable(new Drawable[]{outline, mColoredCircleBackground});
int strokeWidth = (int) (mDensity * 3);
// background.setLayerInset(1, strokeWidth, strokeWidth, strokeWidth, strokeWidth);
background.setLayerInset(0,0,0,0,0);
return background;
}
示例14: setBackgroundDrawable
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
public void setBackgroundDrawable(Drawable drawable, int[] padding) {
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { this.gradientDrawable, drawable});
layerDrawable.setLayerInset(1, padding[0], padding[1], padding[2], padding[3]);
super.setBackgroundDrawable(layerDrawable);
}
示例15: inflateDrawable
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
@Override
protected Drawable inflateDrawable(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException {
final int innerDepth = parser.getDepth() + 1;
int type;
int depth;
int layerAttrUseCount = 0;
int drawableUseCount = 0;
int space = STEP << 1;
//L,T,R,B,S,E,id
int[][] childLayersAttrs = new int[space][ATTRS.length];
Drawable[] drawables = new Drawable[space];
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
&& ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
if (type != XmlPullParser.START_TAG) {
continue;
}
if (depth > innerDepth || !parser.getName().equals("item")) {
continue;
}
if (layerAttrUseCount >= childLayersAttrs.length) {
int[][] dstInt = new int[drawables.length + STEP][ATTRS.length];
System.arraycopy(childLayersAttrs, 0, dstInt, 0, childLayersAttrs.length);
childLayersAttrs = dstInt;
}
updateLayerAttrs(context, attrs, childLayersAttrs[layerAttrUseCount]);
layerAttrUseCount++;
Drawable drawable = getAttrDrawable(context, attrs, android.R.attr.drawable);
// If the layer doesn't have a drawable or unresolved theme
// attribute for a drawable, attempt to parse one from the child
// element.
if (drawable == null) {
while ((type = parser.next()) == XmlPullParser.TEXT) {
}
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException(parser.getPositionDescription()
+ ": <item> tag requires a 'drawable' attribute or "
+ "child tag defining a drawable");
}
drawable = createFromXmlInner(context, parser, attrs);
} else {
final ColorStateList cls = getTintColorList(context, attrs, R.attr.drawableTint);
if (cls != null) {
drawable = ThemeUtils.tintDrawable(drawable, cls, getTintMode(context, attrs, R.attr.drawableTintMode));
}
}
if (drawable != null) {
if (drawableUseCount >= drawables.length) {
Drawable[] dst = new Drawable[drawables.length + STEP];
System.arraycopy(drawables, 0, dst, 0, drawables.length);
drawables = dst;
}
drawables[drawableUseCount] = drawable;
drawableUseCount++;
}
}
if (drawables[0] == null || drawableUseCount != layerAttrUseCount) {
return null;
} else {
LayerDrawable layerDrawable = new LayerDrawable(drawables);
for (int i = 0; i < drawables.length; i++) {
int[] childLayersAttr = childLayersAttrs[i];
if (childLayersAttr[0] != 0 || childLayersAttr[1] != 0 || childLayersAttr[2] != 0 || childLayersAttr[3] != 0) {
layerDrawable.setLayerInset(i, childLayersAttr[0], childLayersAttr[1], childLayersAttr[2], childLayersAttr[3]);
}
if (childLayersAttr[4] != 0) {
layerDrawable.setId(i, childLayersAttr[4]);
}
}
return layerDrawable;
}
}