需要使用google特别提供的NinePatchDrawable,使用方法如下:
public Drawable getNinePatchDrawable(int resid,Rect rect){
InputStream is = getResources().openRawResource(resid);
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inPreferredConfig = Bitmap.Config.RGB_565;
NinePatchDrawable npd = (NinePatchDrawable) Drawable.createFromResourceStream(getResources(), null, is, null, opt);
npd.setBounds(rect);
try{
is.close();
}catch(IOException e){
e.printStackTrace();
}
return npd;
}
如果要对这张9png进行大小设置的话,使用它自带的setBounds就好,上述代码已经包含~