[TIMOB-26853] Add ScaleType support for ImageView
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Critical |
Status | Closed |
Resolution | Duplicate |
Resolution Date | 2021-04-27T22:36:30.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | n/a |
Reporter | Prashant Saini |
Assignee | Joshua Quick |
Created | 2018-12-14T07:54:21.000+0000 |
Updated | 2021-04-27T22:36:30.000+0000 |
Description
For Android platform, currently Ti ImageView automatically calculates the ScaleType based on the defined width-height properties in *updateScaleType* method.
But many times we need the support to define scale types ourselves including the other scale-types as well like *CENTER_CROP / FIT_END / FIT_START / MATRIX*.
*CENTER_CROP* is needed more than other scale-types in most of the apps.
It would also be awesome to have same support on iOS for scale-types if it's possible natively.
Hello [~prashant_saini], Please share the native docs on this feature. We will consider it. Thanks.
Here's the sample code from the Hyperloop which works as expected. You just need to put any *wheel.png* file in *android - res - drawable* folder. {noformat} var Activity = require('android.app.Activity'); var ImageView = require('android.widget.ImageView'); var LayoutParams = require('android.widget.FrameLayout.LayoutParams'); var ViewGroupLayoutParams = require('android.view.ViewGroup.LayoutParams'); var nativeImageView; var i = 0; var scaleTypes = [ ImageView.ScaleType.CENTER_CROP, ImageView.ScaleType.CENTER_INSIDE, ImageView.ScaleType.FIT_CENTER, ImageView.ScaleType.FIT_END, ImageView.ScaleType.FIT_START, ImageView.ScaleType.FIT_XY, ImageView.ScaleType.MATRIX ]; // rotate through the scale-types function changeScaleType(e){ if (i > (scaleTypes.length - 1)) { i = 0; } nativeImageView.setScaleType(scaleTypes[i]); ++i; } var win = Ti.UI.createWindow({backgroundColor : 'white'}); var view = Ti.UI.createView({ top : 20, width : 450, height : 300, backgroundColor : '#888' }); var btn = Ti.UI.createButton({ title : 'Change Scale Type', bottom : 40 }); win.addEventListener('open', function() { var act = new Activity(Ti.Android.currentActivity); var nativeImageView = new ImageView(act); var params = new LayoutParams(ViewGroupLayoutParams.MATCH_PARENT, ViewGroupLayoutParams.MATCH_PARENT); (params != null) && nativeImageView.setLayoutParams(params); nativeImageView.setImageResource(Ti.App.Android.R.drawable.wheel); view.add(nativeImageView); btn.addEventListener('click', changeScaleType); }); win.add(btn); win.add(view); win.open(); {noformat}
As a starting point you could have a look at the old (closed) PR: https://github.com/appcelerator/titanium_mobile/pull/8755 It only adds
aspectFill
but could be extended to accept all other optionsHello [~prashant_saini], Can you please follow up Michael's comment. You should follow up in there. Since we already have a ticket in TIMOB for aspectFill, I believe we could extend to accept other options. If the request is excepted there. we can close this one. Thanks.
Hello [~prashant_saini], I see you haven't followed up in the TIMOB-24313 ticket. Can you please do that. I think we can extend the options presented there. Thanks.
Closing as duplicate of [TIMOB-24313].