Listview 带有旋转标签的Xamarin.Forms列表视图
正在玩Listview 带有旋转标签的Xamarin.Forms列表视图,listview,xamarin.forms,Listview,Xamarin.forms,正在玩Xamarin.Forms,我想创建一个带有旋转标签的列表视图。我设法让标签旋转,但它们彼此重叠。我猜ListView项目的高度不适合旋转 这是我的密码 <ListView Grid.Column="0" x:Name="ListView" BackgroundColor="Black"> <ListView.ItemTemplate> <DataTemplate> <ViewCell>
Xamarin.Forms
,我想创建一个带有旋转标签的列表视图。我设法让标签旋转,但它们彼此重叠。我猜ListView项目的高度不适合旋转
这是我的密码
<ListView Grid.Column="0" x:Name="ListView" BackgroundColor="Black">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ContentView Rotation="-90" VerticalOptions="FillAndExpand" HeightRequest="100">
<Label BackgroundColor="#41b5e8" Text="{Binding}" HorizontalOptions="Center" VerticalOptions="Center"/>
</ContentView>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
更新1:
多亏了亚当·佩德利,我现在轮换正常了。现在我对标签的文本位置有一个问题。我希望它在水平和垂直方向居中,但执行以下操作时,我的文本会显示为关闭
<Grid x:Name="Layout" Grid.Row="1" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<ListView Grid.Column="0" x:Name="ListView" BackgroundColor="Green" SeparatorVisibility="None" HorizontalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ContentView Rotation="-90" BackgroundColor="#41b5e8" VerticalOptions="FillAndExpand" HeightRequest="{Binding Source={x:Reference Label}, Path=Width}">
<Label x:Name="Label" BackgroundColor="Red" Text="{Binding}" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" />
</ContentView>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Grid Grid.Column="1" HorizontalOptions="FillAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid HorizontalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ContentView x:Name="Button1" HorizontalOptions="FillAndExpand" BindingContext="{Binding WeekDay}"/>
<Button Text="DAY 2" Grid.Column="1" HorizontalOptions="FillAndExpand"/>
<Button Text="DAY 3" Grid.Column="2" HorizontalOptions="FillAndExpand"/>
</Grid>
</Grid>
</Grid>
它是这样显示的
如果我将布局网格中的列定义更改为
,我会得到这个结果。
计算中不包括边距,只包括填充。因此,您可能希望向ContentView添加填充
<ContentView Rotation="-90" VerticalOptions="FillAndExpand" HeightRequest="{Binding Source={x:Reference Label}, Path=Width}" Padding="12" >
<Label x:Name="Label" BackgroundColor="#41b5e8" Text="{Binding}" HorizontalOptions="Center" VerticalOptions="Center" />
</ContentView>
你应该试着用填充物代替页边空白。谢谢你,看起来我就快到了。你知道如何解决文本位置问题吗?查看我的更新。我不确定你那边的情况如何,但我会尝试将HorizontalOptions、HorizontalTextAlignment、VerticalOptions和VerticalTextAlignment添加到标签中。一个很好的技巧是设置标签的背景色,并查看一些不同的颜色。然后,它将向您显示哪个组件位于何处以及哪个元素导致对齐问题。一旦我们知道是什么导致了问题,我们就可以集中精力设置这些属性。只是用截图更新了我的帖子,这样你就可以看到问题所在。@Gaz83-只是想澄清一下,你想让图片看起来如何,因为你显示的第一个截图对我来说是正确的,因此,这一定意味着我误解了您需要的确切布局。第一个屏幕截图看起来是正确的,Listview
中的项目位于Listview
的中心。当列表视图
调整大小后,如第二个屏幕截图中所示,这些项目现在不再位于列表视图
的中心。
<ContentView Rotation="-90" VerticalOptions="FillAndExpand" HeightRequest="{Binding Source={x:Reference Label}, Path=Width}" Padding="12" >
<Label x:Name="Label" BackgroundColor="#41b5e8" Text="{Binding}" HorizontalOptions="Center" VerticalOptions="Center" />
</ContentView>