JavaFX - Prevent FlowPane from growing horizontally in VBox - user-interface

How can I prevent the FlowPane layout from growing?
My FlowPane layout is inside a VBox, which has a max width and wraps its content automatically when needed (works with TextFlow and HBox), except with FlowPane.
So my problem is that my FlowPane layout won't observe its maxWidth property.
Also included:
FlowPane messagePane = new FlowPane();
messagePane.setPrefSize(VBox.USE_PREF_SIZE,VBox.USE_PREF_SIZE);
messagePane.setMaxWidth(VBox.USE_PREF_SIZE);
messagePane.setAlignment(Pos.CENTER);
And its content:
Label m = new Label(messageText);
m.setFont(Font.font("Calibri", FontWeight.SEMI_BOLD, 20));
m.setWrapText(true);
m.setAlignment(Pos.CENTER);
m.setTextAlignment(TextAlignment.CENTER);
m.setMaxWidth(FlowPane.USE_PREF_SIZE); //Works with constants only
Why doesn't it work as wanted?

Related

UIScrollView's does not scroll AFTER rendering WKWebView content

Thank you for looking at my question. Currently, I have several input fields and a WKWebView embedded in a UIScrollView. Before any events fire, all the subviews fit inside the scroll view with no issue. I'm dynamically setting the WK's height based on document.body.scrollHeight which is captured in the DidFinishNavigation delegate located in WKNavigationDelegate. After the WK's height is set, the WK extends past the view-able content. Here's the code which I'm trying to force the scrollview to resize itself.
[Export("webView:didFinishNavigation:")] public async void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
{
//get the webView's initial height
var initialHeight = webView.Frame.Height;
//get height of HTML's document.body.scrollHeight
var contentHeight = await GetContentHeight();
//create new frame for webview
CGRect newWebViewFrame = new CGRect(webView.Frame.X, webView.Frame.Y, webView.Frame.Width, contentHeight);
//set webview's frame
webView.Frame = newWebViewFrame;
//get the difference of webView's initial height and webView's current height
var differenceInHeight = contentHeight - initialHeight;
//create new cgrect and set the height to svMain's height + the difference in height of the HTML document
CGRect newScrollViewFrame = new CGRect(0, 0, svMainScroller.Frame.Width, svMainScroller.Frame.Height + differenceInHeight);
//set MainScroller's frame
svMainScroller.Frame = newScrollViewFrame;
//force scrolling
svMainScroller.ScrollEnabled = true;
//scrolling should be handled in the main scroller
webView.ScrollView.ScrollEnabled = false;
svMainScroller.SizeToFit();
}
The desired effect is to have the scroll view be able to scroll to the end of the newly defined height. Any tips on how would I go about doing that would be greatly appreciated.
Updating the frame of the scroll view was the problem. My guess is that if the frame is big enough to contain all of the contents, then there's no need to scroll. So, I updated the scroll view's ContentSize instead of updating its frame.
svMainScroller.ContentSize = new CGSize(View.Frame.Width, View.Frame.Height + differenceInHeight);
Also, as a side note, verify that wkwebview is added as a subview to the scroll view and not the main view.

How to set padding/margin for the children inside a Linear Layout in Xamarin.Android?

I can able to set padding for linear layout. But I need to set padding for the children inside a linear layout. Please find my codes below,
LinearLayout linear1 = new LinearLayout(BaseContext);
TextView textView = new TextView(BaseContext);
linear1.AddView(textView,100,100); (or) linear1.AddView(textView,LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.MatchParent);
SetContentView(linear1);
Now I need to set padding for the TextView loaded inside a linear layout. Is it possible?
Thanks in advance.
We can set padding for the children inside a linear layout like below,
LinearLayout linear1 = new LinearLayout(BaseContext);
TextView textView = new TextView(BaseContext);
linear1.AddView(textView,100,100);
LinearLayout.LayoutParams options = (LinearLayout.LayoutParams)textView.LayoutParameters; //where textView is the view loaded inside a linear layout.
options.LeftMargin = 30;
options.TopMargin = 30;
options.RightMargin = 30;
options.BottomMargin = 30;
SetContentView(linear1);
you can call linear1.SetPadding(int,int,int,int);

Xamarin horizontal view with buttons

any ideas how to prepare such an element as at the picture ?
I need 5 buttons to be there so i could swipe through them but only 3 one them are visible all the time. I need this to work on android and ios in xamarin forms.
Try this Add ScrollView and set it's orientation to horizontal
ScrollView = new ScrollView
{
Orientation = ScrollOrientation.Horizontal
};
//ScrollView.Scrolled += ScrollView_Scrolled;
ItemsStackLayout = new StackLayout
{
Orientation = StackOrientation.Horizontal,
Padding = new Thickness(0),
Spacing = 0,
HorizontalOptions = LayoutOptions.FillAndExpand
};
ScrollView.Content = ItemsStackLayout;
you can set the width of the elements inside 1/3 of the view width
FYI I use the same in my app

How to style individual slots in a Vaadin GridLayout?

I want to have a border on some of the slots in my GridLayout.
If I set the border on the element within the slot (with the help of a style name), the border is not drawn all the way.
How can I access the enclosing gridlayout-slot, so that every other slot has a border?
I recommend you put a CssLayout in the GridLayout and style that like this:
final GridLayout gridLayout = new GridLayout(2, 2);
// the size of the grid layout has to be defined, otherwise you can't place a relatively sized component inside it
gridLayout.setHeight("400px"); // example height
gridLayout.setWidth("100%"); // example width
final CssLayout border = new CssLayout();
border.setStyleName("myCellStyle");
// make the layout fill the whole slot
border.setSizeFull();
// wrap your content with that border layout
border.addComponent(new Label("forth"));
gridLayout.addComponents(
new Label("first"),
new Label("second"),
new Label("third"),
border);
In your mytheme.scss write your border style:
.myCellStyle {
border: 10px solid red;
}

Adding space in Xamarin.Forms layouts?

What's the proposed way to add space to layouts in Xamarin.Forms?
One way would be to add a Frame with no children like so:
new Frame {
BackgroundColor = Color.White,
HeightRequest = 1,
MinimumHeightRequest = 1,
HasShadow = false
}
Unfortunately, HeightRequest and MinimumHeightRequest get ignored.
Does a better way exist?
You could put your controls inside layouts (like frame, scroll view, stack panel) and use Padding property:
this.stackPanel = new StackLayout ()
{
Padding = new Thickness (8, 8)
};
var scrollView = new ScrollView ()
{
Content = stackPanel,
Padding = new Thickness (1, 2, 3, 4)
};
var frame = new Frame ()
{
Padding = new Thickness (8)
};
If you want space between two buttons for example, I believe this would do the trick. The first one adds 10 to bottom padding, the second adds 10 to top padding for total of 20.
var frame1 = new Frame ()
{
Padding = new Thickness (0,0,0,10),
Content = new Button()
};
var frame2 = new Frame ()
{
Padding = new Thickness (0,10,0,0),
Content = new Button()
};
Most Xamarin.Forms Layouts supports adding space between elements:
StackLayout has a Spacing property,
Grid has RowSpacing and ColumnSpacing properties,
...
Now, if you want to add spacing at a particular place, the way to to it is to include a BoxView:
myStackLayout.Children.Add (new BoxView {Color = Color.Transparent, HeightRequest = 5});
You can also wrap your content in a Frame or ContentView, but it adds padding to the content instead of adding space (although the effect will be the same).
What I do worked perfectly for me:
Suppose you want to distribute 2 Labels evenly on a horizontal StackLayout:
new StackLayout
{
Orientation = StackOrientation.Horizontal,
HorizontalOptions=LayoutOptions.CenterAndExpand,
Spacing = 0, // <- Very important!!
Children = {
new Label { Text = "Label 1" },
new BoxView { HorizontalOptions = LayoutOptions.FillAndExpand }, // <- the clever part
new Label { Text = "Label 2" }
}
};
Summary
By inserting BoxViews that fill the remaining space ("FillAndExpand") between your views, your views appear evenly distributed.
By setting Spacing = 0, you don't get extra space between your views.
Try:
myFrame.TranslateX=10;
myFrame.TranslateY=10;
I wanted to share a screenshot in conjunction with Lay González's answer but the edit queue was full->
To get dynamic spacing similar to CSS "Space-Between" in Xamarin you can insert filler views between your views that actually have content.
Here is an example:
Omit the filler view after the last "actual" view so that the view you want is at the end (the "-50" label at the bottom in the example).

Resources