gpt4 book ai didi

c# - Xamarin 形成细胞操作 RTL

转载 作者:太空宇宙 更新时间:2023-11-03 21:01:47 25 4
gpt4 key购买 nike

目前我已经使用以下 XAML 构建了一个 ListView

<ListView x:Name="_lstMenu" VerticalOptions="FillAndExpand" BackgroundColor="Transparent">
<ListView.ItemTemplate>
<DataTemplate>
<ImageCell Text="{Binding Title}" ImageSource="{Binding IconSource}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

我想做的是,当语言切换为阿拉伯语时,整个用户体验都是从右到左的。为此,我使用了 RotateYTo(180) 方法。

protected override void rotateElementsY(int rotationY)
{
base.rotateElementsY(rotationY);

foreach (View sub in subviews())
{
sub.RotateYTo(rotationY);
}
}

private View[] subviews()
{
View[] _subs = new View[] {
imgUser, lblGreetings, lblUserName, lstMenu, stkBottom};
return _subs;
}

到目前为止它运行良好,除了 ImageCell,因为我只能在从左到右的方向上显示它,并且无法旋转 Cell 的任何子项(标签、图像)。

PS:我也试过镜像 ListView 后把单元格的阿拉伯文字倒写,但还是不合适。

最佳答案

感谢 ganchito55 启发我找到我需要的答案。我几乎使用了他制作 RTL 的想法,但也有能力在需要时更改为 LTR。

<ListView x:Name="_lstMenu" VerticalOptions="FillAndExpand" BackgroundColor="Transparent">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="6*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<Image Source="{Binding IconSource}" IsVisible="{Binding isEnglish}"/>
<Label Grid.Column="1" Text="{Binding Title}" VerticalTextAlignment="Center" HorizontalTextAlignment="{Binding alignment}"/>
<Image Grid.Column="2" Source="{Binding IconSource}" IsVisible="{Binding isArabic}"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

如您所见,我已将另一个图像添加到项目模板,并向列出的项目对象添加属性,以决定每次显示哪个图像和对齐方式。

关于c# - Xamarin 形成细胞操作 RTL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44870667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com