5

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);  

        ...       
    }

    ...     
}
javad
  • 833
  • 14
  • 37

2 Answers2

4

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.

Community
  • 1
  • 1
laalto
  • 150,114
  • 66
  • 286
  • 303
  • i removed targetSdkVersion, but it dosent work.my pictures are in asset folder. – javad Jan 20 '14 at 11:59
  • Of course single-resolution image in assets will look smaller on a higher-density display. So, edit the question and show how you are decoding/scaling the images. – laalto Jan 20 '14 at 12:02
  • what about 2 picture of android 4.1. i just remove and everything work perfectly. – javad Jan 20 '14 at 12:07
  • I've explained that in the first paragraph. It's not perfect, rather an upscaled compatibility mode. – laalto Jan 20 '14 at 12:08
0

Thanks alot friends

I edited <use-sdk ... /> to

<uses-sdk android:minSdkVersion="1" android:targetSdkVersion="1" />

and added @SuppressLint("NewApi") to above of MapCanvas

my problem solved!

javad
  • 833
  • 14
  • 37
  • 1
    This is an awful "solution". You should use actual min/target values for SDK versions in manifest and scale any "dp" values in code to screen pixel values based on density. The question I linked in my answer has some pointers towards that. – laalto Jan 21 '14 at 10:23