Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different output in Android 4.1

I've run my program on Android 2.3 and Android 4.1 but pictures of my app shown very tiny in android 4.1:

enter image description here

I remove <uses-sdk android:minSdkVersion="5" android:targetSdkVersion="14" /> in manifest.xml and my app work perfectly on both:

enter image description here

but I dont want to remove <uses-sdk android:minSdkVersion="5" android:targetSdkVersion="14" />

Where is my problem?

abstract of my code is:

public class MapCanvas extends ImageView
{    
    ...

    public MapCanvas(Context context) 
    {
        super(context); 
    }

    public MapCanvas(MainActivity context, Bundle state) 
    {
        super(context);                 

        this.context = context; 

        ... 
    }               

    ...

    @Override
    protected void onDraw(Canvas canvas) 
    {                               
        super.onDraw(canvas);               

        ...

        //Paint Offset X, Y, Zoom
        this.paint.setColor(Color.rgb(51, 51, 51)); 
        this.paint.setFakeBoldText(true);
        this.paint.setTextSize(15);
        String text = "X:" + OFFSET_X + ", Y:" + OFFSET_Y + ", Zoom:" + MapZoom.Zoom;                                                     
        canvas.drawText(text, 5, 15, paint);  

        ...       
    }

    ...     
}
like image 869
javad Avatar asked Oct 02 '22 19:10

javad


1 Answers

Removing targetSdkVersion makes it implicitly 1, enabling all backwards compatibility modes, including UI scaling for apps targeting below API level 4. That explains why removing the uses-sdk "fixes" the problem.

To fix your code, you will have to scale your pixel sizes and measures with screen density.

like image 106
laalto Avatar answered Oct 05 '22 12:10

laalto