Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27508] Android: Ti.UI.Button with image is rendered incorrectly

GitHub Issuen/a
TypeImprovement
PriorityMedium
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterHans Knöchel
AssigneeUnknown
Created2019-10-29T08:54:28.000+0000
Updated2019-12-12T20:24:38.000+0000

Description

When using a Ti.UI.Button with an image that is set to a smaller ratio than the physical image size, it is rendered incorrectly (example image is attached):
var win = Ti.UI.createWindow();
var btn = Ti.UI.createImageView({ width: 20, height: 22, image: 'example.png' });
win.add(btn);
win.open();
Expected behavior: The image is rendered correctly. Actual behavior: See below. !Bildschirmfoto 2019-10-29 um 09.50.15.png|thumbnail! This works fine on iOS and bugs us since ages. Please fix this parity issue.

Attachments

FileDateSize
Bildschirmfoto 2019-10-29 um 09.50.15.png2019-10-29T08:54:11.000+00005867
example.png2019-10-29T08:53:42.000+00003243
MaskYinYang.png2019-10-29T21:47:51.000+000010020

Comments

  1. Alan Hutton 2019-10-29

    [~hknoechel] Can you provide more information in the issues? I don't want to guess as to what configuration/environment since with Android, it could be a number of things. Please include SDK version, Simulator (or Device for DPI), Android API version, etc.. I am not able to reproduce the issue with SDK 8.2.1.GA.. I've tried on Pixel 3a Device and emulator (API 29), and Pixel 3a emulator (API 28), and for reference, iPhone 11 iOS 13.0.
  2. Hans Knöchel 2019-10-29

    I think it's related to density specific images, e.g. Resources/android/images/xxhdpi/example.png (scale 3x) and Resources/android/images/xhdpi/example.png (scale 2). I can try to prepare a sample project, but ideally that already exists internally at Appc.
  3. Joshua Quick 2019-10-29

    [~hknoechel], this is happening because you are setting the height on the button. Yes, there is a platform/parity difference here, but neither approach is necessary wrong/buggy either. On iOS, the image will be "scaled" to fit the size of the button. However, it does not scale the image evenly. The image will appear "squished" if you make the height shorter. On Android, the image will be loaded as-is and "clipped" within the button's bounds. This doesn't look great either if the button height is too short. In my opinion, the best approach is don't set the button height. Leave it as Ti.UI.SIZE so that the button can fully display the image without it being clipped/squished. Try testing it with the attached "MaskYinYang.png" image that I've attached to this ticket and you'll see what I mean. *Side Note:* I think the iOS code should be changed to scale the image evenly to get rid of the squished effect. We can change the Android code to do the same. But for now, neither look good.

JSON Source