当前位置: 首页>>代码示例>>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;未经允许,请勿转载。