【发布时间】:2020-09-04 08:17:10
【问题描述】:
我打算在 Listview 项目出现时编码“项目出现”项目从 top 或 bottom 出现。 (使用 TranslateTo)
但是当 Listview Viewcell Appearing 或 itemsAppearing 出现时,我尝试应用动画。 但是,较高的项目索引隐藏了较低的项目动画索引。 因此,较低索引项的动画仅在短期内显示。 (被其他布局裁剪)
Please Check Image Description _ Animation Cropped by items
在 Xamarin 表单中(C#)
private async void ItemsListView_ItemAppearing_1(object sender, ItemVisibilityEventArgs e)
{
int i = e.ItemIndex;
int y;
y = 400;
for (int d = 0; d < i; d++)
{
int z = d + 1;
y = y + (400 / (z * z));
}
uint x = uint.Parse(y.ToString());
IEnumerable<PropertyInfo> pInfos = (ItemsListView as ItemsView<Cell>).GetType().GetRuntimeProperties();
var templatedItems = pInfos.FirstOrDefault(info => info.Name == "TemplatedItems");
if (templatedItems != null)
{
var cells = templatedItems.GetValue(ItemsListView);
var cell = (cells as Xamarin.Forms.ITemplatedItemsList<Xamarin.Forms.Cell>)[e.ItemIndex] as ViewCell;
//cell.View.Opacity = 0;
cell.View.TranslationY = Var.Device_Height / Var.Device_Scale;
await cell.View.TranslateTo(0, 0, x, Easing.CubicOut);
}
}
在 XAML 中
<ListView x:Name="ItemsListView" BackgroundColor="Transparent" VerticalOptions="Fill" ItemsSource="{Binding Items}" Margin="0" SeparatorVisibility="None" RefreshCommand="{Binding LoadItemsCommand}"
IsPullToRefreshEnabled="True" HasUnevenRows="True" IsRefreshing="{Binding IsBusy, Mode=OneWay}" ItemAppearing="ItemsListView_ItemAppearing_1"
>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell Appearing="ViewCell_Appearing">
<ViewCell.View>
<Frame IsClippedToBounds="False"
Margin="0,5"
CornerRadius="10"
Padding="0"
HasShadow="False"
BorderColor="#f0f0f0"
BackgroundColor="Transparent" >
<StackLayout Padding="0" Spacing="0" MinimumHeightRequest="0">
<StackLayout Orientation="Horizontal">
<Label Text="{Binding Name}" Margin="13,12,5,0" FontAttributes="Bold" FontSize="18" TextColor="#222222">
</Label>
<Frame MinimumHeightRequest="0" VerticalOptions="EndAndExpand" Padding="7,2,7,2" CornerRadius="100" BackgroundColor="Accent" HasShadow="False">
<Label Text="{Binding Sequence}" TextColor="White" FontSize="Micro"/>
</Frame>
</StackLayout>
<Label Text="{Binding Mail}" Margin="13,6,0,12">
</Label>
</StackLayout>
</Frame>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
当 ViewCell_appearing 或 items_Appearing
时,结果相同【问题讨论】:
-
我放慢了你的动画,这里正在运行 GIF。 imgur.com/a/KFQIZ6Y,我在
ViewCell_Appearing中设置了你的代码,高索引项不隐藏低索引项动画 -
我不知道您为
Var.Device_Height / Var.Device_Scale;设置的值是多少所以,我设置了测试值。public static double Device_Height = DeviceDisplay.MainDisplayInfo.Height;和public static double Device_Scale = 6;