Xamarin Forms Stacklayout StackOrientation.Horizontal - xamarin

When i set StackOrientation.Horizontal for stacklayout and setting 5 labels it displays properly.
But when the number of labels count is increased labels text size reduced and all labels are aligned for available width.
How to display full text for all labels also move label to next line if the labels count exceeds?

Use WrapLayout instead:
var layout = new WrapLayout {
Orientation = StackOrientation.Horizontal,
HorizontalOptions = LayoutOptions.Fill,
Padding = new Thickness (0, padding, 0, padding)
};
layout.Children.Add (item);
Result:

StackLayout with Horizontal orientation will only use "one line".
For that case you should use a GridLayout or WrapLayout (From Xlabs).
In alternative you could use a StackLayout with Horizontal orientation and each Child is a StackLayout with Vertical orientation.

Xamarin 3.0 introduced FlexLayout for exactly this use-case. It's based on CSS Flexboxes.

Related

Strange behavior with Grid definition auto height and stacklayout inside the row

I am using a grid with autoheight for row definition (I have a Editor inside, so my row can update it's height depending of the text).
My issue is, in another cell, there is a stack layout
StackLayout stackEspeceVariete = new StackLayout()
{
Children = { autoCompleteEspece, autoCompleteVariete }
};
stackEspeceVariete.Orientation = StackOrientation.Horizontal;
gridLignes.Children.Add(stackEspeceVariete);
Grid.SetRow(stackEspeceVariete, gridLignes.RowDefinitions.Count - 1);
Grid.SetColumn(stackEspeceVariete, 2);
Adding the stacklayout cause my row to take all the screen size. I want the stacklayout to take the size it's needed, not all screen size.
I tried changing the vertical option but no success.
I also tried to fix the stacklayout height to 130, it's was "working" but, the row height was no longer changing, depending on the editor text.
It's like the row is fixed to the stacklayout child
Do you have any idea ?
Thanks

Sub 10 height request layouts/views not allowed

I'm trying to add line dividers between views. However, there is a forced margin on every element I try (Image, BoxView, Frame, Label). I set the margin to be 0, the HeightRequest is always 3, but as you can see the view bounds expand past the actual view. Is there a specific view I'm supposed to be using? I just want the gray line and nothing more.
var line2 = new Frame
{
WidthRequest = (App.ScreenDpWidth / 2),
MinimumHeightRequest = 3,
HeightRequest = 3,
BackgroundColor = Color.FromHex("#229EBB"),
Margin = new Thickness(0, 0)
};
I assume you are layouting your elements either in a Grid or a StackLayout.
By default, the StackLayout.Spacing, Grid.RowSpacing and Grid.ColumnSpacing properties are set to 6d.
Without more information, I think that's what you're seeing in your code. Change those values to 0d.
Also, if you only want a gray line, you can use a BoxView which will draw a gray box, and set it's Height to 1d.

How can I control the width of the X-axis labels on a horizontal bar RadChart?

What are the properties that control the width of the X-axis labels on a horizontal bar RadChart? Here's what it looks like now:
I need the labels on the left to be wider.
I actually, just needed to keep the auto layout doing its thing, and disable auto wrapping this way:
var item = new ChartAxisItem();
item.Appearance.RotationAngle = AutoTextWrap.False

titanium view height and contents

I am new to Titanium and try to understand the how the views works and i am facing a problem.
I have create a view that contains one image and 2 labels.
var row = Titanium.UI.createTableViewRow({height:'auto'});
var item_view = Titanium.UI.createView({
height:'100%',
layout:'vertical',
top:5,
right:5,
bottom:5,
left:5
});
var item_image = Titanium.UI.createImageView({
url:imageUrl, // the image for the image view
top:0,
left:0,
height:97,
width:65
});
item_view.add(item_image);
var productName_lbl = Titanium.UI.createLabel({
text:productName,
left:70,
width:'auto',
top:-97,
bottom:2,
height:'auto',
textAlign:'left',
color:'#444444',
font:{fontFamily:'Trebuchet MS',fontSize:12,fontWeight:'bold'}
});
item_view.add(productName_lbl);
var comName_lbl = Titanium.UI.createLabel({
text:comName,
left:70,
width:'auto',
top:7,
bottom:2,
height:'auto',
textAlign:'left',
color:'#444444',
font:{fontFamily:'Trebuchet MS',fontSize:12,fontWeight:'bold'}
});
item_view.add(comName_lbl);
The problem is that the image has height 97px but both labels on left have smaller height.
The result is the image is now showing 100% but only show according the height of labels on left.
keep in mind that labels maybe really long texts so i have on labels width,height auto
i tried to change the row height from auto to 100% but still not working.
Any help appreciated
Try Titanium 2.0. It solves lots of these types of rendering issues.
You can read about it on their wiki Titanium 2.0 Layout Changes
I was having problems with View elements filling out to be the height of the screen (as opposed to the height of the elements it contains) and after reading the layout changes link from JC Guerrero (thanks JC!), I Added:
Ti.UI.createView(height: Ti.UI.SIZE, ...
and it successfully auto-adjusted the view's height to match it's contents
[edit] Removed quotation mark, and it works well, thanks!
Titanium calculate elements height badly, if you use 'vertical' layout. So you must set their height's by yourself, or remove layout property for 'absolute' positioning.

BlackBerry - Resize the width of horizontal manager

Is it possible to resize the width of horizontal manager. I want to create two buttons in horizontal manag, set the background border. I am using the following code for that. It is working fine. But as there are only two buttons and doesn't occupy the entire screen of 320 width, setting border is happening only for those two buttons background. So i could see the white space apart from the horizontal width in forward and backward spaces. So i want to create a Horizontal manager itself with 320 width, so that setting border color will show for the entire width. Is it possible to resize the width of horizontal manager?
XYEdges borderColor = new XYEdges(Color.BLACK, Color.BLACK, Color.BLACK, Color.BLACK);
XYEdges noPadding = new XYEdges(2, 2, 2, 2);
HorizontalFieldManager hzBtnFldManager = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER);
createButton = new CustomControl("Create", ButtonField.FOCUSABLE | ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER, 83, 15);
cancelButton = new CustomControl("Cancel", ButtonField.FOCUSABLE | ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER, 83, 15);
hzBtnFldManager.add(createButton);
hzBtnFldManager.add(cancelButton);
Border btnBarPaddingBorder = BorderFactory.createSimpleBorder(noPadding, borderColor, Border.STYLE_SOLID);
hzBtnFldManager.setBorder(btnBarPaddingBorder);
hzBtnFldManager.setBackground(BackgroundFactory.createSolidBackground(Color.GRAY));
this.setStatus(hzBtnFldManager);
Maybe try using the Field.USE_ALL_WIDTH style on the HorizontalFieldManager?

Resources