温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

DrawableView

发布时间:2020-07-17 06:37:48 来源:网络 阅读:763 作者:hlp666666 栏目:移动开发
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);
    }


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI