To occupy the whole width or height , I use double.infinity, but going through some of the flutter samples, I have noticed many people use MediaQuery.of(context).size.width or height. I went through the docs but there are no differences mentioned between this two or when to use which one as both allow same feature. Are they specific to particular widgets?
The difference can be summarized into:
I want to be as big as my parent allows (double.infinity)
I want to be as big as the screen (MediaQuery).
Usually, you'll want to use double.infinity, but it's not always possible.
Some Widgets allow their children to be as big as they want to be (Column, ListView, OverflowBox...). In that situation using double.infinity creates a paradox:
The parent allows any size
The child wants the biggest size allowed by the parent
Using MediaQuery in these situations is bad though. You will rarely want to do that unless you're creating a widget similar to Scaffold.
That's where widgets such as IntrinsincHeight comes in handy. These widgets are able to solve the paradox, and therefore have a valid layout.
MediaQuery occupies the space as per the screen size whereas double.infinity occupies the space as parent size. It could be matched with match-parent in Android.
Related
I just bought the Apple Watch and I want to create a super simple game for it.
It is simple enough to only use monochrome color scheme, but advanced enough to have an object moving in real-time.
I am trying to figure out how to position an object on my Apple Watch with Watch OS 2.
I want to place my object somewhere on the screen (anywhere I'd like to) but there are absolutely
no way to do that, I think.
But, in the following library: https://github.com/shu223/watchOS-2-Sampler
the developer can actually animate the alignment of the image so I guess
that itself suggests it should be possible to somehow specify a point of where to position an object.
And the animation is pretty smooth as well.
I have tried to generate frames on-the-fly CGContext which uses Quartz 2D, but it's way too slow and the app on my Apple Watch just crashes.
I don't necessarily think that the watch itself is too weak, but some clever programming should solve my problem, but I just cant figure out how to do it.
As you already said there is no way to directly position an WKInterfaceObject on your watch. You can change the alignment of an object but that leaves exactly 3 positions: left, center and right. Probably not enough for your game.
What you could do: You can set a background image on a WKInterfaceGroup. So you could draw your game objects into an UIImage and set that as background image of that group. That background images can also be animated. So maybe you can draw the movement of your game object into several UIImages and then set those as animated background image.
One way that I have found to have a little more control over where a WKInterfaceObject is on the screen is to add it to a parent WKInterfaceGroup, and center your item (vertically and/or horizontally depending on how you want to move it). Then you can tweak the group's relative height / width (setRelativeHeight and setRelativeWidth) and it's alignment (setVerticalAlignment and setHorizontalAlignment) to get your item positioned where you want.
This doesn't give you the ability to tweak frames or give the item a particular coordinate, but it does give you the ability to programmatically move a WKInterfaceObject anywhere on the screen.
For example if you want your object in the exact center of the screen vertically, you leave the group's relative height to its container as 1, with your item centered. To get the object at 40% from the top, you can change the group's relative height to 0.8 and it's alignment to .Top. If you want it 60% from the top, the relative height would still be 0.8, but the group's vertical alignment should be .Bottom etc.
I know this is kind of a confusing way to have to accomplish this, but this worked for me in getting items positioned exactly how I wanted.
I'm writing an application with kivy that scans a network and based on results it generates bunch of widget like labels and buttons or maybe a layout like Gridview.
I'm trying to position them by pos or center_x and center_y attributes. I can position them perfectly on my laptop but when I try my tablet or other devices with different screen sizes everything goes wrong and all widgets change their position.
My question is:Is there a elegant way to position widgets and layouts that pertain their position on any screen size?
P.S:
it's not working even when i maximize the window.
You have many different options here like::
Query the Window size and position your widget relative to the window using percentages instead of absulute values.
Use specific layout that fits the positioning style you need for you widgets.
Recomended
Use pos_hint in combination with your layouts
specify the widget pos using kivy.metrics.dp which gives you device independent pixels or use metrics.sp/cm/mm/in/...
I want to make use of the setExtent() method in blackberry.
Every time i use setExtent(), it allocates the space from the zero, zero coordinate to any custom field that i paint by extending the Field class.
I want when I draw any custom field from (100,100), then it should allocate space from (100,100) and not from (0,0).
my code looks like:
protected void layout(int width,int height)
{
setExtent(100,100);
}
Please help me out with any solutions.
What you appear to be trying to do actually doesn't sound like a very good idea. 100 pixels is a useful measure on one device, but 100 pixels on a 9300 is over 1/3 of the height of the screen, but on a 9800 is no where near that. I would strongly recommend that you do not use fixed pixel sizes for any Blackberry development.
That said, if you want to Field to start at position 100,100, you should use setPositionChild for that Field in the Field's Manager.
Before you start leaping off attempting this, I would recommend that you review the following:
http://supportforums.blackberry.com/t5/Java-Development/How-to-Extend-Manager/ta-p/446749
and
http://supportforums.blackberry.com/t5/Java-Development/Create-a-custom-layout-manager-for-a-screen/ta-p/442990
But perhaps the best options might be to explain what you are trying to achieve and we might be able to suggest an alternative.
I was wondering: I have a background image on a site I'm working on that needs to be very exactly positioned. Currently, its positioning is:
body {
...
width: 100%
background-position-x: center;
background-position-y: -10px;
}
This works pretty well -- for the most part the image stays centered in the x axis when a user resizes a window.
However, if the user resizes the window to an odd pixel width (ie body becomes 1001px not 1000px) then the background image seems to be positioned off by a bit (maybe 1 pixel?).
How can I fix this? Do I have to limit the element width to even numbers/how do I do this? Is there maybe a jQuery solution to this?
EDIT: A site named Simplegeo https://simplegeo.com/ manages to do this perfectly. Notice the tiled background: it's made with a repeated png file, and it's always perfectly positioned against the elements on the page. This shows it's possible.. but does anyone know how they did it?
The way I see it, you got two options:
1) Resize the users window till to the closest even number (when a resize happens), something like this http://jsfiddle.net/hATKW/
2) Use a fixed width along with media queries to account for multiple sized windows, read on Media Queries here: http://css-tricks.com/6731-css-media-queries/
Thanks,
Leo
This website uses a background image which is 20x20 pix (even number). You may use
body {
min-width:400px;
}
At this width 1px off will be hardly be detectable and if the user re-sizes to larger window, the difference will be hardly noticeable.
I am not exactly sure about your question though. You are talking about element in the question, not the background. Would be helpful if you provide your site link.
I have used the coin slider.But the coin slider is restricted by the width.I need to run my application in various screen size like 1280*768,800*600.is there any image slider in jquery without restrict width of image?Please help me.
Thanks in advance.
Most image sliders are designed for being placed within a container of a certain width, so that they fit within a specific slot in a layout. Given that the size of the screen/window(you don't specify) is irrelevant to that, it seems like what you're looking for is a gallery that adapts to the size of the entire window, rather than fit within a specific size.
You should probably widen your search to JS galleries in general, which might have that option or even function that way in the first place. As initial suggestions, have a look at the full-screen example for Galleria, or maybe the Supersized plugin