Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3412] Android: Auto width/height resource drawables should be sized as they are in native Android

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionInvalid
Resolution Date2017-06-08T23:29:21.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsandroid, defect, reported-1.6.0
ReporterBill Dawson
AssigneeEric Merriman
Created2011-04-15T03:44:00.000+0000
Updated2017-06-08T23:29:21.000+0000

Description

Given a native android project (non-titanium) with the following:

  • This layout xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" >
<ImageView 
    android:src="@drawable/test" 
    android:id="@+id/iv" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
/>
</LinearLayout>
  • A file, test.png, in res/drawable-mdpi. The file is a 50 pixel by 50 pixel graphic.

  • The application running on a high-density device.

When rendered, the image view will be 75 x 75 pixels (50 * 1.5), because the graphic file was in the mdpi (medium density) drawable folder and the device is a high density device, so Android automatically scales it up.


Given a Titanium project with the following:

  • The same test.png from above (50x50) in the project's platform/android/res/drawable-mdpi folder.

  • The following app.js:

Titanium.UI.setBackgroundColor('#000');
var win = Titanium.UI.createWindow({  
    title:'Test',
    backgroundColor:'#000',
    exitOnClose: true
});

var iv = Ti.UI.createImageView({
    left: 0, top: 0, height: 'auto', width: 'auto',
    image: Ti.App.Android.R.drawable.test
});
win.add(iv);

var btn = Ti.UI.createButton({
    top: '50%', height: 'auto', width: 'auto', left: 0,
    title: 'Get dimensions'
});
btn.addEventListener('click', function(){
    var size = iv.size;
    Ti.API.info("ImageView dimensions: " + size.width + "x" + size.height);
});
win.add(btn);
win.open();

When run, and when clicking the "Get dimensions" button, the logcat output will show that the rendered width and height remain at 50x50, so the image was not scaled up automatically. I believe it should have been.

Expected outcome: The logcat output from the above Titanium project should show "ImageView dimensions: 75x75".

Comments

  1. Bill Dawson 2011-04-15

    The reason: TiDrawableReference (responsible for fetching and scaling images), when it gets images that are resource drawables, uses Resources.openRawResource() and checks the bounds of that raw drawable -- which are 50x50. It doesn't know where the resource comes from (i.e., from which drawable-?dpi resource folder it comes from), so even if it tried to scale it (which it doesn't even try), it wouldn't know whether it should scale it and by how much to scale it.

  2. Lee Morris 2017-06-08

    Closing ticket as there has been no input for the last 6 years. Any problems, please file a new ticket.

JSON Source