Appcelerator Titanium - don't stretch image to ImageView dimentions - appcelerator

I have an image of size 1024x1024 and I want to have it a background as an ImageView object. I've set the ImageView height and width to be the size of the device and loaded the image - what happens is that the image shows the entire image squeezed to the given dimensions.
What I would like to see is not the entire image - I want it to scale to show it centered, and the parts of the image that don't fit the screen to not show. What my end result should be just setting the height and the width whatever is disposable will be overflowed and hidden.
How can I set an image not to stretch?

What your looking for is a clipped image. This affect is best achieved using a combination of View with clipping turned on and an ImageView.
As an example, we'll use a large image and the code below.
<Alloy>
<Window class="container" backgroundColor="#000">
<View clipMode="Titanium.UI.iOS.CLIP_MODE_ENABLED" width="200">
<ImageView image="/images/Moonset_over_ESO's_Very_Large_Telescope.jpg" height="2336" width="3504"/>
</View>
</Window>
</Alloy>
Note that we have enabled clipping on the parent View, and are using it to define the actual width we want everything rendered on the Screen. The ImageView is then used with the actual width / height of the image to be rendered. Because we are not setting a top,left,right,bottom properties, the ImageView will render itself centered in the parent view, with its overflow hidden.
This provides the desired effect as shown in the image below.

I think you mean the image property of the ImageView and not the backgroundImage. If you use a normal view and set the backgroundImage it will be stretched. From the docs:
Specifying either a width or height property for this view will scale
its image(s) with the aspect ratio maintained, up to a maximum size
that does not exceed its parent view.
If you want to center the image you could just place it in a View and set the width/height to the max value (or calculate the aspect ratio and set both values corretly) and it will be centered in the surrounding View
XML
<Alloy>
<Window >
<ImageView id="img"/>
</Window>
</Alloy>
JS
$.img.image = "/images/1.jpg";
$.img.width = 200;
$.index.open();
Image original size: 1080x720. Display inside the app: 200px width not stretched and in the middle of the window (Android, Ti 5.1.2, TiShadow on device)

Related

Why is the footer image not aligned to the bottom of the view?

I'm trying to use storyboard and layout constraints to align the footer image to the bottom of the view but when running on device it's hovering high above the bottom. The image is aligned with 0 margin to the superview. The view hierarchy is Controller->View->ScrollView->View->FooterImage. The image is bigger and scaled with content mode set to "aspect fit".
The constraints set on the image is sufficient, but I guess the constraints set on its super View is incorrect.
If you want to display the image at bottom you also need to make it superView align to the bottom of the ScrollView , and the same on ScrollView.
Check my previous answer here : https://stackoverflow.com/a/46539635/8187800 .

JavaFx image resizing

I have a borderPane with a menu top,a grid left and an image in the center.I want the image to have the same size as the center of the border because now the image goes over my grid.
I tried this:
imageView.fitWidthProperty().bind(box.widthProperty());
where imageView is the name for my image and box is the BorderPane object.Thank you.
See JavaFX Feature Request RT-21337 Add ImageViewPane and MediaViewPane controls which contains a code attachment for a sample ImageViewPane implementation which which will resize the ImageView it contains to the area available to the region. To get the behaviour required you might also need to implement computeMinWidth and computeMinHeight on the ImageViewPane so that they return zero rather than the minimum size of the Image.
now the image goes over my grid
This is because the minimum size of your image is currently larger than the available space of the center of your BorderPane:
BorderPane does not clip its content by default, so it is possible that childrens' bounds may extend outside its own bounds if a child's min size prevents it from being fit within it space.
Some potential alternatives to prevent the center content overflowing the border:
Manually set a clip on the center node to prevent it overflowing the borders.
Dynamically resize the ImageView as in the ImageViewPane sample linked above.
Place the ImageView in a ScrollPane.
Use the css -fx-background-image attributes to display and dynamcially resize your image rather than using an ImageView.
Set the center of the borderpane first before setting the border content, that way it will be rendered underneath the border content.
Use a different construct from a borderpane (e.g. a HBoxes, VBoxes, etc.) which don't overlap their nodes when the nodes are larger than the available display area.
I tried this: imageView.fitWidthProperty().bind(box.widthProperty());
My guess from the code provided is that this didn't work because the enclosing box of the image is a dynamically resizable pane of some sort, so the minimum width of the box is being determined by the width of the image and not vice versa.

Getting Windows 8 UI Control to fill entire horizontal space

For a Windows 8 Metro app, I have a Rectangle inside of a Canvas inside of the main Grid, such that:
<Grid>
...
<Canvas>
<Rectangle />
...
</Canvas>
</Grid>
How would I make the rectangle dynamically take up the width of the screen?
Canvas does not constrain or change its children's size or positions. If you want your rectangle to be as long as the screen width I recommend to put it inside the Grid, as the Grid has the size you need for the Rectangle (with HorizontalAlignment="Strech"). Or you might bind Rectangle.Width to Grid.ActualWidth.

Android URL Image

Given an Image URL - it should show the URL in the image view
The entire screen should be occupied by this image - Do not break the aspect ratio - nor chop off any part of the image - it is ok to have some black area on the x axis or y axis to preserve the aspect ratio
The Imageview should adjust orientation as the device is moved to landscape & portrait mode.
To just show an image, you may as well use the ImageView by setting layout parameters.
Suppose you want add zoom/pan functionality, then you will have to extend ImageView.
This link should help you
Shash

UIScrollView scroll when orientation changes

I create a UIScrollView, in which I put a UIView. Then I add some objects which are subviews of the view I added to the UIScrollView, so that I can zoom properly all the objects within the scroll.
The point is that I have an UIImageView as a subview of the mentioned view, which contains an image which is adapted to the screen size by using "imageView.contentMode = UIViewContentModeScaleAspectFit;" property.
Initially, in portrait orientation, the image fits with the screen width, so you can't scroll to left or right. When I change orientation to landscape, image fits with screen top and bottom. Then my problem. You can scroll up and down a little bit the image, as if it preserved some of the top and bottom padding from the portrait orientation.
But, if I try to zoom out, as the min zoom I setted was 1,0, the image recovers its initial size. Then you can't zoom out anymore when the zoom scale is 1.0. The 'virtual' padding is gone!
It seems as if it needed some kind of refresh.
The same happens when I keep changing orientation for portrait and landscape. It only works correctly when app loads.
I tried setting "myUIScrollView.zoom = 1.0;" in "didRotateFromInterfaceOrientation" method (when the image was not zoomed) and it worked, the 'virtual' padding again was gone.
It seems that it needs a refresh once orientation changes.
Any clue about what I'm doing wrong?

Resources