I am placing content in the grid list component and I want the grid tile to grow accordingly to the content it has. I tried to use rowHeight="fit" as documentation states but it doesn't seems to work.
Here an example
MatGridList overall size is directly related to the rowHeight setting. The default rowHeight value is a ratio 1:1 (which means column width equals row height).
When you use a ratio, the list will have a fixed width/height ratio overall, so if the list can't grow in one direction because of window or layout restrictions, it can't grow in any direction. This is why your example looks the way it does. If you expand the width of the window, you'll see the list expand vertically as well. You can set a different rowHeight value to make the tiles taller than wide such as rowHeight="1:2" (that seems backwards to me but that's how it works).
When you use rowHeight="fit", this doesn't fit the list to the content, it fits the row heights to the list height, but as noted in the documentation, you must set a height on the list or a parent for this to work properly.
Setting a fixed value for rowHeight does what it sounds like.
Related
I’ve been asked this question on a job interview and I’m wondering what he meant.
The role of hugging and compression properties for any view with intrinsic content size is obvious.
But what about views without intrinsic content size? Do they play a role there?
Kind of an odd question, without some additional context.
However, I suppose you could discuss a couple things...
Some views get an intrinsic content size after-the-fact. A UIImageView, for example... without an image, it has no intrinsic content size. But once you set its .image property, its intrinsic content size will be the size of the image. So, you may want to set the priorities based on what will happen.
You can give a UIView, for example, "Placeholder" intrinsic content size. Changing the hugging/compression priorities will affect that view during design-time.
In both of those cases, you would be "planning ahead" during Storyboard / IB design for what you want at run-time.
EDIT
Here is a (rather long) example:
Here I have a UIView (green) containing a UIStackView set to Fill / Fill / 8. The stack view holds a UIImageView (Scale To Fill) and a UILabel. The image view has NO intrinsic content size, while the label has an intrinsic content size, based on its content.
With the constraints I've set, the stack view is 200 x 240 points.
At run-time, I'm going to set the image to a 200 x 100 png of a cat:
My goal is for the image view to "fit to the image," letting the label expand vertically.
When I set the .image via code (at run-time), the image view "gets" an intrinsic content size (of 200 x 100 in this case). With both the image view and the label having Vertical Content Hugging: 251 (the default), this is the result:
But I want the image to retain its original aspect ratio of 2:1. First thought is to change the image view's Content Mode to Aspect Fit -- but I get this result:
Now my image view is "letter-boxing" the image, showing the red background color.
So, I change the image view's Vertical Content Hugging: 252 (higher priority than the label). The output:
Now I have the run-time output that I want, but at design-time (working in Storyboard / IB), nothing has changed and it may not really be clear what's going to happen.
So, I give the image view a Placeholder intrinsic content size of 200 x 100, and I see this:
Because it's a placeholder, that will have no effect on the run-time output (if I set the image to a 200 x 50 image it will be 200 x 50 at run-time), but it better reflects what I'm expecting.
Of course, there are other ways to accomplish the goal, and this may not be the ideal approach, but it (hopefully) gives an idea of one way that setting Hugging / Compression priorities on elements with no intrinsic content size can be useful / needed.
I'd like to resize UICollectionViewCell to fit image that is sensibly resized and maintains dimensions/aspect ratio. If I simply set the size of cell to size of image it may be way too big. Also, If I run on different sized devices, the spacing isn't consistent. Must I implement collectionView programmatically to overcome this?
I see many apps that do this so its a very common problem that may already be solved as a framework.
Example:
UICollectionView is actually of arbitrary layout. It so happens that the default is UICollectionViewFlowLayout which is a grid, but you can change it to anything by implmenting your own instance of the UICollectionViewLayout protocol. Int the case you cited its pretty easy. The width of the cells is the collectionview (width minus the padding) divided by two. The height is the aspect ratio times the width + the spacing + the label height. all the cells with indices divisible by 2 go in the right column and the rest go in the left column. It should be easy to calculate these values for layoutAttributesForItem(at:). Unfortunately its a bit harder to calculate for collectionViewContentSize. Assuming your collectionview is sufficiently small I think its best to just precalculate all of the hieghts and use the cached values for these functions.
There're a lot of open sources on github You can refer to.
https://github.com/zhangsuya/SYStickHeaderWaterFall
I am trying to create this layout, but I am struggeling so badly that I have no words left for it. I have tried for three days but yet I can't create the layout.
I am trying to have the three imageviews in the middle scale if the height of the view changes, but they are not behaving correct. I have successfully manage to get the ratios correct though, but the images either goes behind the blue button, or the blue button suddenly looses its height or the text disappears.
Isn't it possible to have three image views in the middle that take whatever height is left after the title and text + blue button have been laid out and then properly show them with correct ratios?
You can try multiple approaches here:
Size Classes:
Lay out the views for each possible size (probably the easiest but the least flexible
Use Constraints with different priorities:
You can set a max-height for the image views by adding a constraint for the height and then setting its relationship to equal or less than. This allows the image to scale up until a maximum size is reached.
Then add a second constraint between the bottom box and the images. Set the priority of this constraint to 750. This makes the image grow in height, when the bottom view moves down.
Then add another constraint which sets the aspect ratio of the image. If you use the mode of the view to Aspect Fit, the image will now always be scaled up to fit the image view.
To make all images scale proportionally, add constraints for equal width and equal height between them, then set the factor to match the proportions between these images.
The last step is now to vertically align the images properly as you showed in the pictures. To do that, add constraints between the images, which align them by their vertical centers, bottoms, baselines or tops.
I have gone through a couple of Auto Layout tutorials such as this. However I am still not clear on what the following options do in the pin dialog
What are the differences between standard value, manual values, and canvas values?
What does the constrain to margin checkbox do?
What does align do?
What are the differences between standard value, manual values, and canvas values?
Standard value uses "the recommended spacing for constraints that specify distance between items", which is usually around 10 points.
Current canvas value copies the value from how you have the objects currently displayed on the canvas.
Manual values are whatever you want.
What does the constrain to margin checkbox do?
This constrains to a container view's margins instead of its edges. From the docs:
“Horizontal and vertical constraints to a container view can be to the margin or to the edge. Margins correspond to the values in the layoutMargins atttribute of UIView and specify recommended minimal distances between an edge of a container view and the corresponding edge of a child.”
You can set a view's margins using the layoutMargins property.
What does align do?
This creates a constraint that edges or center of one view should be aligned with edges or center of another view. For example, in a column of text views, you might want every text field to have their leading and trailing edges aligned.
I am working inside a Tabpane and I want to have 2 buttons on the bottom-right of the tap-pane, so I thought I just add a LayoutSpacer, but this resulted in
but I wanted it to look like
How can I make my Layoutspacer "bigger"?
In Smart GWT there are different methods to set the size of the component's vertical dimension.
Try with any one
canvas.setHeight100()
canvas.setHeight("100%")
canvas.setHeight("*")
Layouts may specially interpret percentage sizes on their children, and also allow "*" as a size.