相关疑难解决方法(0)

如何将中心对齐位图?

我希望我的位图位于我的屏幕中心..我试着这样但它不起作用......

Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.compass);

            int w = canvas.getWidth();
            int h = canvas.getHeight();

            int bw=myBitmap.getWidth();
            int bh=myBitmap.getHeight();

            int cx = w / 2;
            int cy = h / 2;

            Display d = getWindowManager().getDefaultDisplay();
            int x = d.getWidth();
            int y = d.getHeight();
            int dx = x / 2;
            int dw = y /2;
            canvas.translate(cx, cy);    
            if (mValues != null) {
                canvas.rotate(-mValues[0]);
            }  

            int centreX = (x  - bw) /2;

                int centreY = (cy - bh) /2;  
            //canvas.drawPath(mPath, mPaint);
            canvas.drawBitmap(myBitmap, centreX,centreY, …
Run Code Online (Sandbox Code Playgroud)

android

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

android ×1