Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26853] Add ScaleType support for ImageView

GitHub Issuen/a
TypeNew Feature
PriorityCritical
StatusClosed
ResolutionDuplicate
Resolution Date2021-04-27T22:36:30.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterPrashant Saini
AssigneeJoshua Quick
Created2018-12-14T07:54:21.000+0000
Updated2021-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.

Comments

  1. Sharif AbuDarda 2019-01-19

    Hello [~prashant_saini], Please share the native docs on this feature. We will consider it. Thanks.
  2. Prashant Saini 2019-01-19

    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}
  3. Michael Gangolf 2019-01-19

    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 options
  4. Sharif AbuDarda 2019-02-01

    Hello [~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.
  5. Sharif AbuDarda 2019-02-12

    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.
  6. Joshua Quick 2021-04-27

    Closing as duplicate of [TIMOB-24313].

JSON Source