當前位置: 首頁>>代碼示例>>Java>>正文


Java NinePatchDrawable類代碼示例

本文整理匯總了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;
    }
}
 
開發者ID:hoangkien0705,項目名稱:Android-UtilCode,代碼行數:23,代碼來源:ImageUtils.java

示例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);
}
 
開發者ID:florent37,項目名稱:Depth,代碼行數:24,代碼來源:DepthRelativeLayoutContainer.java

示例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;
}
 
開發者ID:Pingsh,項目名稱:Mix,代碼行數:25,代碼來源:ThemeUtils.java

示例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;
    }
}
 
開發者ID:JackWHLiu,項目名稱:jackknife,代碼行數:20,代碼來源:ImageUtils.java

示例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;
    }
}
 
開發者ID:imliujun,項目名稱:LJFramework,代碼行數:26,代碼來源:ImageUtils.java

示例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;
		}
	}
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:22,代碼來源:ForegroundRelativeLayout.java

示例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;
		}
	}
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:22,代碼來源:ForegroundLinearLayout.java

示例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();
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:19,代碼來源:DrawShadowFrameLayout.java

示例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);
}
 
開發者ID:AstinPE,項目名稱:FloatingApps,代碼行數:19,代碼來源:PopupMenu.java

示例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);
 }
 
開發者ID:AstinPE,項目名稱:StarchWindow,代碼行數:19,代碼來源:PopupMenu.java

示例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;
}
 
開發者ID:Bilibili,項目名稱:MagicaSakura,代碼行數:25,代碼來源:ThemeUtils.java

示例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);
}
 
開發者ID:kevenwu,項目名稱:Android-Yet-Another-Refresh,代碼行數:26,代碼來源:CircularImageView.java

示例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;
    }
}
 
開發者ID:canyinghao,項目名稱:CanPhotos,代碼行數:26,代碼來源:CanViewPagerActivity.java

示例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);
}
 
開發者ID:xujiaji,項目名稱:HaiNaBaiChuan,代碼行數:22,代碼來源:DepthRendrer.java

示例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;
    }
}
 
開發者ID:Alex-Jerry,項目名稱:LLApp,代碼行數:27,代碼來源:DanMuHelper.java


注:本文中的android.graphics.drawable.NinePatchDrawable類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。