How to align center a bitmap?

后端 未结 2 885
深忆病人
深忆病人 2021-01-02 11:00

i want my bitmap in the center of my screen..i m trying it that way but its not working...

Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.d         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-02 11:48

    You can try this :

            int width = containerBitmap.getWidth();
            int height = containerBitmap.getHeight();
            float centerX = (width  - centeredBitmap.getWidth()) * 0.5f;
            float centerY = (height- centeredBitmap.getHeight()) * 0.5f;
    

    You can use it to draw a bitmap at the center of another bitmap.

提交回复
热议问题