Question

I'm new on android and I've made an widget that shows battery % but on my phone (Galaxy nexus) shows fine, but on other with different density it shows very big. I've search already in every place but I didnt found any solution that makes the build bitmap shows good in every mobile... can someone please help me?

public Bitmap buildBitmap(String texto, Context context) {

    Bitmap myBitmap = Bitmap.createBitmap(94, 94, Bitmap.Config.ARGB_4444);
    Typeface font = Typeface.createFromAsset(context.getAssets(),
            "batmfont.ttf");

    Paint paint = new Paint();

    paint.setAntiAlias(true);
    paint.setSubpixelText(true);
    paint.setTypeface(font);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.WHITE);
    paint.setTextSize(35);
    paint.setShadowLayer(1, 1, 1, Color.rgb(51, 51, 51));
    paint.setTextAlign(Align.CENTER);

    Canvas myCanvas = new Canvas(myBitmap);
    myCanvas.drawText(texto, 47, 54, paint);

    return myBitmap;
}
Was it helpful?

Solution

Get the screen dimensions and Resize a bitmap.

So based on your device size you can display bitmap.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top