BitmapDrawable mBitmapDrawable ; int x=1; int y = 1; int w=0; int h=0; public DrawableView(Context context) { super(context); /*读取res->drawable文件下的图片*/ mBitmapDrawable = (BitmapDrawable) getResources().getDrawable(R.drawable.box); //w = mBitmapDrawable.getIntrinsicWidth();//460 // h = mBitmapDrawable.getIntrinsicHeight();//434 DisplayMetrics dm = new DisplayMetrics(); w = dm.widthPixels; h=dm.heightPixels; Log.i("test",w+","+h); if (mBitmapDrawable != null) { mBitmapDrawable.setBounds(x,y,w,h);//画一个矩形,x,y是起点,w是矩形的宽,h是矩形的高,图片就显示在矩形中 mBitmapDrawable.setGravity(Gravity.CENTER_HORIZONTAL);//图片在矩形中居中显示 } // mBitmapDrawable.setAntiAlias(true); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); mBitmapDrawable.draw(canvas); Paint p = mBitmapDrawable.getPaint(); p.setTextSize(30); p.setColor(Color.BLUE); canvas.drawText("宝箱",50,50,p); }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。