Height of ContentPage gets set to 504? - xamarin

I've had my share of "what the f%$#" Xamarin forms errors. But this one tops the cake. I've spent about 3 hours now trying to figure out why this page only gets set to 504 height, and nothing I do seems to fix it. Literally have a empty page like so:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:XamarinMobile.Controls;assembly=XamarinMobile"
xmlns:local="clr-namespace:XamarinMobile.Classes;assembly=XamarinMobile"
xmlns:converters="clr-namespace:XamarinMobile.Converters;assembly=XamarinMobile"
xmlns:viewModels="clr-namespace:XamarinMobile.ViewModels;assembly=XamarinMobile"
xmlns:customRenderers="clr-namespace:XamarinMobile.CustomRenderers;assembly=XamarinMobile"
x:Class="XamarinMobile.CommentsPage">
<Label Text="Test"></Label>
</ContentPage>
And I get this result:
Literally it's identical to other pages that don't have this problem. Any insights? Any way to force it to be a minimum height of screen height? So annoying.

You could manually set the height of a layout to match the screen.
App.ScreenWidth = (int)UIScreen.MainScreen.Bounds.Width;
App.ScreenHeight = (int)UIScreen.MainScreen.Bounds.Height;
Then set a relative or stacklayout to height / width to the results. I think you would be better off taking a look at https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/ and using perhaps a stacklout layout with vertical option set to fill. I would expect that to match screen height.

So the issue seemed to be that I wasn't calling a method I needed to call.
NavigationPage.SetHasNavigationBar
https://developer.xamarin.com/api/member/Xamarin.Forms.NavigationPage.SetHasNavigationBar/p/Xamarin.Forms.BindableObject/System.Boolean/
The behavior of this is odd. It 'allocates' space for a navigation bar if you don't specify it at all. You'd think it'd default to false, but seems like it defaults to true. Setting it false fixed the issue:
Xamarin.Forms.NavigationPage.SetHasNavigationBar(this, false);

Related

Xamarin Forms Iphone X remove padding

I've tried everything to remove the top padding in IPhone X, including setting this on the page code behind:
var safeInsets = On<iOS>().SafeAreaInsets();
safeInsets.Top = 0;
Padding = safeInsets;
and in Xaml
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
ios:Page.UseSafeArea="False"
ios:Page.PrefersStatusBarHidden="True"
NavigationPage.HasNavigationBar="False"
Still getting this padding at the top. I'm probably missing or not understanding something. I've read all the Xamarin guides, many forum posts, etc. How do I get the image to go all the way to the top?

macOS NSStackView content does not fill the available space

I use a NSStackView to dynamically (added by code) display other NSViews, everything works so far, but the sub views are to small.
They try to be as small as possible, regardless the constrains, if i resize the views in IB, they scale correctly
The Header with the hide button does not fill the available space:
I did set the translatesAutoresizingMaskIntoConstraints property to false on the stackview and all subviews
Well, it's hard to know for sure without more information, but the most likely cause is that the horizontal content hugging priority of the labels is higher than the horizontal hugging priority of the stack view. (Note: the former is a general property of all views while the latter is a stack-view-specific property.)
You also need to have constraints between the stack view and its superview to make the stack view stretch the full width. For example, leading and trailing space constraints.
This is quite old, but in modern times I have found that if you set the alignment to width, everything magically works.
stackView.orientation = .vertical
stackView.alignment = .width
stackView.addArrangedSubview(nowFullWidthSubview)

Scrollview in Interface Builder with Autolayout with content size dynamically set to screen size?

I want to set the content view of a scrollview to whatever the current screen size is, but AutoLayout is doing some funky stuff. This is trivial in code... just create a scrollview with a frame that is the superview's bounds. Then create a content view with the scrollview bounds and populate it and set the alwaysBounces... properties to YES. In interface builder though, this is some kind of sinful thing it seems.
I know Autolayout handles scrollviews totally differently because it wants to infer the content size based on constraints. My approach that failed is setting the scrollview to have 0 distance to its superview (all sides attached). Then, the same with the content view (the single scrollView subview)- attached to all superview edges. Then the precompiler thing complains about not knowing the content size, so I set a width and height constraint at placeholder to be removed at build time. But the result is a (CGRect){0,0,0,0} contentView. The 0 space to trailing edge and bottom of superview are totally ignored.
So how can I make a scrollview with a dynamic content size based on the screen size?
Bonus points if you can explain how you would do the same, but for a content size of 2x screen width.
You can try setting a constraint for the content view's width to equal the scroll view's width (for your bonus question: with a multiplier of 2). Same for height.
Not sure what the point of having a scroll view whose content is always the size of the scroll view is. By definition it wouldn't scroll, right?

How to do this simple thing with XCode's new Auto Layout feature?

Im trying to do something that seems like it should be a no-brainer. But alas, im too dumb to figure this one out. So i need help.
I have an iphone simulator (with a vertical orientation).
The main view has a subview (a blue UIView) that should be displayed in the bottom 25% of the screen. The final rendered screen would basically look like a white screen with the bottom section being blue.
I want the edges of the subview to hug the screen edge. But thats not the part I'm struggling with. The tricky thing is configuring the height of this subview (and the layout of its contents, if any) when I suddenly rotate the orientation of the simulator. If i do this, then everything looks odd.
I would also like to note that what I see in the Interface Builder (with Auto Layout enabled) looks nothing like the app when it loads in the simulator.
PS - for now i will keep playing around with this. maybe i will eventually reach a eureka moment.
* Updated with screen shots *
This is what my layout looks like in Interface Builder:
And this is what it ends up looking like in the simulator:
* Update 2 *
Ok. After updating my post with the screenshots, it dawned on me that the simulator doesn't look like the 4" screen version (even though it does on my computer screen). After running the 4" simulator i can see the the layout just like the IB layout. But this makes me wonder why auto-layout wasn't "smart" enough to adjust for the smaller 3.5" screen.
It looks to me like you have a fixed height constraint from the top edge of the blue view to the superview that is pushing content down - conversely you may have a fixed height view above it that is smooshing things. Try pinning the top edge of the blue view to the superview and lowering the priority or changing it from an equality to a less than equal to constraint.
In IB in XCode you can change the canvas size for iPhone layouts, look for the single button on the right hand side that looks like a rectangle with arrows above and below, or inside it. In the screenshot below it is the leftmost button.
You could simply turn off Auto Layout. Springs and struts can readily make your subview 25% of the superview's height.
Or, you can certainly stick with it, but you'll need to adjust the constraints in code. There's no way to establish such a constraint in the current version of Xcode. Set constraints in IB to pin the box to the bottom of the window and fix the height, setting an outlet for the height constraint. Then in -viewDidLoad, remove the height constraint and add a new constraint to the superview which expresses the height relationship you want.
This isn't to discourage you from learning Auto Layout, but to point out that it's a bit complicated, and that the constraint tools in IB are unintuitive and relatively weak. The WWDC video Introduction to Auto Layout is a good starting point.

Set background to an listview

I want to set an background to my listview that have different size (depending the appearance of softkeyboard). My list view is in between the editboxes and I want my editboxes always to be visible (means I do not want to use adjustPan).
My problem comes in the moment when the android adjust the size of my listview and the background get tweaked. I want my background to remain the same, just to be cropped.
and I want to look something like this
Is there any style that I can add that will make the image act like this, the point is to do NOT do an resize and to fill the whole available area. And to DO something like a CROP , means to show as much as there is an space and then the rest just to be cropped.
I found some workaround for the problem I want to solve. I set the scaleType with "centerCrop" value and it seems to work fine.
I hope this will save time to someone else having this problem...
Try in your Manifest to add
android:windowSoftInputMode="adjustPan" or "adjustUnspecified"
for your <activity
Read more about values here:
http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft
I would put the listview in a linearlayout and put the background on the linearlayout.
As for the textbox at the top, if you have not figured that out, use relativelayout.
Here is a good link about the view being re-sized by the keyboard:
http://groups.google.com/group/android-developers/browse_thread/thread/be5ffe40c2bc29f0?pli=1
Here is a good link for the button staying on top:
Add Image at above of listview

Resources