本文整理匯總了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;
}
}