[英]Reducing the height of horizontal listview - xamarin forms
我正在嘗試獲取水平滾動的水平列表視圖,其中包含一些數字(0-23)作為項目。
我將listview設置為水平,但是listview的高度沒有包裝到內容上。 我嘗試將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
}
};
我是xamarin的新手,可能是我走的路是錯誤的。 如果是這樣,請向我建議合適的一個。.但總的來說,我希望使用僅包含數字作為項目的水平listview,並且希望將高度包裝到內容中。
請任何幫助將是不小的..在此先感謝..
如果要在列表視圖中自動設置項目的高度,則必須在XAML文件中使用HasUnevenRow="true"
。
例:
<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.