本文整理汇总了Java中android.graphics.drawable.NinePatchDrawable类的典型用法代码示例。如果您正苦于以下问题:Java NinePatchDrawable类的具体用法?Java NinePatchDrawable怎么用?Java NinePatchDrawable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NinePatchDrawable类属于android.graphics.drawable包,在下文中一共展示了NinePatchDrawable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawable2Bitmap
import android.graphics.drawable.NinePatchDrawable; //导入依赖的package包/类
/**
* drawable转bitmap
*
* @param drawable drawable对象
* @return bitmap
*/
public static Bitmap drawable2Bitmap(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
} else if (drawable instanceof NinePatchDrawable) {
Bitmap bitmap = Bitmap.createBitmap(
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
} else {
return null;
}
}
示例2: setup
import android.graphics.drawable.NinePatchDrawable; //导入依赖的package包/类
void setup() {
setLayerType(LAYER_TYPE_HARDWARE, null);
getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
if (child instanceof DepthRelativeLayout) {
boolean hasChangedBounds = ((DepthRelativeLayout) child).calculateBounds();
if (hasChangedBounds)
invalidate();
}
}
return true;
}
});
shadowPaint.setColor(Color.BLACK);
shadowPaint.setAntiAlias(true);
softShadow = (NinePatchDrawable) getResources().getDrawable(R.drawable.shadow, null);
roundSoftShadow = getResources().getDrawable(R.drawable.round_soft_shadow, null);
}
示例3: containsNinePatch
import android.graphics.drawable.NinePatchDrawable; //导入依赖的package包/类
public static boolean containsNinePatch(Drawable drawable) {
drawable = getWrapperDrawable(drawable);
if (drawable instanceof NinePatchDrawable
|| drawable instanceof InsetDrawable
|| drawable instanceof LayerDrawable) {
return true;
} else if (drawable instanceof StateListDrawable) {
final DrawableContainer.DrawableContainerState containerState = ((DrawableContainer.DrawableContainerState) drawable.getConstantState());
//can't getBaseApplication containState from drawable which is containing DrawableWrapperDonut
//https://code.google.com/p/android/issues/detail?id=169920
if (containerState == null) {
return true;
}
for (Drawable dr : containerState.getChildren()) {
dr = getWrapperDrawable(dr);
if (dr instanceof NinePatchDrawable
|| dr instanceof InsetDrawable
|| dr instanceof LayerDrawable) {
return true;
}
}
}
return false;
}
示例4: drawable2Bitmap
import android.graphics.drawable.NinePatchDrawable; //导入依赖的package包/类
public static Bitmap drawable2Bitmap(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
} else if (drawable instanceof NinePatchDrawable) {
Bitmap bitmap = Bitmap
.createBitmap(
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
} else {
return null;
}
}
示例5: drawable2Bitmap
import android.graphics.drawable.NinePatchDrawable; //导入依赖的package包/类
/**
* drawable转bitmap
*
* @param drawable drawable对象
* @return bitmap
*/
public static Bitmap drawable2Bitmap(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
} else if (drawable instanceof NinePatchDrawable) {
Bitmap bitmap = Bitmap
.createBitmap(drawable.getIntrinsicWidth(), drawable
.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE
? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable
.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
} else {
return null;
}
}
示例6: ForegroundRelativeLayout
import android.graphics.drawable.NinePatchDrawable; //导入依赖的package包/类
public ForegroundRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundRelativeLayout,
defStyle, 0);
final Drawable d = a.getDrawable(R.styleable.ForegroundRelativeLayout_foreground);
if (d != null) {
setForeground(d);
}
a.recycle();
if (this.getBackground() instanceof NinePatchDrawable) {
final NinePatchDrawable npd = (NinePatchDrawable) this.getBackground();
mRectPadding = new Rect();
if (npd.getPadding(mRectPadding)) {
mUseBackgroundPadding = true;
}
}
}
示例7: ForegroundLinearLayout
import android.graphics.drawable.NinePatchDrawable; //导入依赖的package包/类
public ForegroundLinearLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundRelativeLayout,
defStyle, 0);
final Drawable d = a.getDrawable(R.styleable.ForegroundRelativeLayout_foreground);
if (d != null) {
setForeground(d);
}
a.recycle();
if (this.getBackground() instanceof NinePatchDrawable) {
final NinePatchDrawable npd = (NinePatchDrawable) this.getBackground();
mRectPadding = new Rect();
if (npd.getPadding(mRectPadding)) {
mUseBackgroundPadding = true;
}
}
}
示例8: DrawShadowFrameLayout
import android.graphics.drawable.NinePatchDrawable; //导入依赖的package包/类
public DrawShadowFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
final TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.DrawShadowFrameLayout, 0, 0);
mShadowDrawable = a.getDrawable(R.styleable.DrawShadowFrameLayout_shadowDrawable);
if (mShadowDrawable != null) {
mShadowDrawable.setCallback(this);
if (mShadowDrawable instanceof NinePatchDrawable) {
mShadowNinePatchDrawable = (NinePatchDrawable) mShadowDrawable;
}
}
mShadowVisible = a.getBoolean(R.styleable.DrawShadowFrameLayout_shadowVisible, true);
setWillNotDraw(!mShadowVisible || mShadowDrawable == null);
a.recycle();
}
示例9: showAtLocation
import android.graphics.drawable.NinePatchDrawable; //导入依赖的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);
}
示例10: showAtLocation
import android.graphics.drawable.NinePatchDrawable; //导入依赖的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);
}
示例11: containsNinePatch
import android.graphics.drawable.NinePatchDrawable; //导入依赖的package包/类
public static boolean containsNinePatch(Drawable drawable) {
drawable = getWrapperDrawable(drawable);
if (drawable instanceof NinePatchDrawable
|| drawable instanceof InsetDrawable
|| drawable instanceof LayerDrawable) {
return true;
} else if (drawable instanceof StateListDrawable) {
final DrawableContainer.DrawableContainerState containerState = ((DrawableContainer.DrawableContainerState) drawable.getConstantState());
//can't get containState from drawable which is containing DrawableWrapperDonut
//https://code.google.com/p/android/issues/detail?id=169920
if (containerState == null) {
return true;
}
for (Drawable dr : containerState.getChildren()) {
dr = getWrapperDrawable(dr);
if (dr instanceof NinePatchDrawable
|| dr instanceof InsetDrawable
|| dr instanceof LayerDrawable) {
return true;
}
}
}
return false;
}
示例12: onDraw
import android.graphics.drawable.NinePatchDrawable; //导入依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
final Drawable drawable = getDrawable();
if (null == drawable)
return;
if (drawable instanceof NinePatchDrawable)
return;
final int width = getWidth();
final int height = getHeight();
final int layer = canvas.saveLayer(0, 0, width, height, this.nonePaint,
Canvas.ALL_SAVE_FLAG);
drawable.setBounds(0, 0, width, height);
drawable.draw(canvas);
if ((null == this.mask) || (this.mask.isRecycled())) {
this.mask = createOvalBitmap(width, height);
}
canvas.drawBitmap(this.mask, 0, 0, this.maskPaint);
canvas.restoreToCount(layer);
drawBorder(canvas, width, height);
}
示例13: drawable2Bitmap
import android.graphics.drawable.NinePatchDrawable; //导入依赖的package包/类
/**
* Drawable 转 bitmap
*
* @param drawable
* @return
*/
public Bitmap drawable2Bitmap(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
} else if (drawable instanceof NinePatchDrawable) {
Bitmap bitmap = Bitmap
.createBitmap(
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
} else {
return null;
}
}
示例14: setup
import android.graphics.drawable.NinePatchDrawable; //导入依赖的package包/类
void setup() {
getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
if (child instanceof DepthLayout) {
boolean hasChangedBounds = ((DepthLayout) child).calculateBounds();
if (hasChangedBounds)
invalidate();
}
}
return true;
}
});
shadowPaint.setColor(Color.BLACK);
shadowPaint.setAntiAlias(true);
softShadow = (NinePatchDrawable) getResources().getDrawable(R.drawable.shadow, null);
roundSoftShadow = getResources().getDrawable(R.drawable.round_soft_shadow, null);
}
示例15: drawable2Bitmap
import android.graphics.drawable.NinePatchDrawable; //导入依赖的package包/类
/**
* Drawable转换成Bitmap
*
* @param drawable
* @return
*/
public Bitmap drawable2Bitmap(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
// 转换成Bitmap
return ((BitmapDrawable) drawable).getBitmap();
} else if (drawable instanceof NinePatchDrawable) {
// .9图片转换成Bitmap
Bitmap bitmap = Bitmap.createBitmap(
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ?
Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
} else {
return null;
}
}