[英]Reducing the height of horizontal listview - xamarin forms
I am trying to get a horizontal listview scrolling horizontally having some numbers(0-23) as items in it. 我正在尝试获取水平滚动的水平列表视图,其中包含一些数字(0-23)作为项目。
I am getting the listview as horizontal but the height of the listview is not getting wrapped to the content. 我将listview设置为水平,但是listview的高度没有包装到内容上。 I tried using RelativeLayout with xConstraint, yConstraint, width and heightConstraint, I tried changing the parameter values in it but the listview disappears all the times I change the values.
我尝试将RelativeLayout与xConstraint,yConstraint,width和heightConstraint结合使用,尝试更改其中的参数值,但是每次更改值时listview都会消失。
ListView lv = new ListView
{
SeparatorVisibility = SeparatorVisibility.None,
ItemsSource = items,
Rotation = 270,
ItemTemplate = new DataTemplate(() =>
{
Label label = new Label()
{
Rotation = 90,
TextColor = Color.Black,
HorizontalTextAlignment = TextAlignment.Center,
FontSize = Device.GetNamedSize(NamedSize.Small, new Label())
};
label.SetBinding<User>(Label.TextProperty, indexer => indexer.Time);
return new ViewCell
{
View = new StackLayout
{
Children =
{
label
}
}
};
})
};
RelativeLayout rLayout = new RelativeLayout();
rLayout.Children.Add(lv,
xConstraint: Constraint.RelativeToParent((parent) =>
{
return (parent.Width / 0.5) - 30;
}),
yConstraint: Constraint.RelativeToParent((parent) =>
{
return (parent.Height / -0.5) + 3;
}),
widthConstraint: Constraint.Constant(60),
heightConstraint: Constraint.RelativeToParent((Parent) =>
{
return (Parent.Height / 10);
})
);
Content = new StackLayout
{
Children = {
rLayout
}
};
I am new to xamarin, may be the way I am going is wrong. 我是xamarin的新手,可能是我走的路是错误的。 If so please suggest me the right one.. But as of total I want a horizontal listview having only numbers as items and I want the height to be wrapped to the content.
如果是这样,请向我建议合适的一个。.但总的来说,我希望使用仅包含数字作为项目的水平listview,并且希望将高度包装到内容中。
Please any help would be appreciable.. thanks in advance.. 请任何帮助将是不小的..在此先感谢..
If you want to make auto height of items inside the listview then you have to use HasUnevenRow="true"
in your XAML file. 如果要在列表视图中自动设置项目的高度,则必须在XAML文件中使用
HasUnevenRow="true"
。
Example: 例:
<ListView x:Name="SomeList" HasUnevenRows="True" ItemsSource="{Binding ...}" SeparatorVisibility="None">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Label HorizontalOptions="CenterAndExpand" TextColor="Blue" Margin="0,5,0,5" Text="{Binding ....}" FontSize="Small" HeightRequest="35"/>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.