我尝试了很多建议,但没有任何作用!当我在后台线程中调用Thread.sleep()时,主线程也会冻结此时间(动画帧丢弃):(
版本1:
public void UpdateChannels(final ArrayList<Channel> channels)
{
new AsyncTask<ArrayList<Channel>, Object[], Void>()
{
@Override
protected Void doInBackground(ArrayList<Channel>... arrayLists)
{
for(Channel channel : arrayLists[0])
{
Integer chid = new Integer(channel.arfcn);
ChannelRect channelRect = Channels.get(chid);
publishProgress(new Object[] {channelRect, channel.dBm});
try
{
Thread.sleep(1000);
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
return null;
}
@Override
protected void onProgressUpdate(Object[]... values)
{
ChannelRect channelRect = (ChannelRect) values[0][0];
int value = (Integer)values[0][1];
channelRect.setValue(value);
channelRect.Animate();
}
}.execute(channels);
}
Run Code Online (Sandbox Code Playgroud)
版本2:
public void UpdateChannels(final ArrayList<Channel> channels)
{
new Thread(new …Run Code Online (Sandbox Code Playgroud) 我有两个动画:
<Storyboard x:Key="ChangeLayout">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Canvas.Left)" Storyboard.TargetName="currentContent">
<EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="900"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0">
<EasingDoubleKeyFrame.EasingFunction>
<CircleEase EasingMode="EaseInOut"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="HideLayout">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Canvas.Left)" Storyboard.TargetName="currentContent">
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="-900">
<EasingDoubleKeyFrame.EasingFunction>
<CircleEase EasingMode="EaseInOut"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
Run Code Online (Sandbox Code Playgroud)
以及开始它们的代码:
private void btnUser_Click(object sender, RoutedEventArgs e)
{
if (currentContent.Content != null)
if (currentContent.Content.GetType() == typeof(Layouts.User))
return;
((hl.Children[0] as DoubleAnimationUsingKeyFrames).KeyFrames[0] as EasingDoubleKeyFrame).Value = -this.ActualWidth;
hl.Completed += (_sender, _e) =>
{
currentContent.Content = new Layouts.User();
cl.Completed += (ssender, ee) =>
{
btnMusic.Opacity = 0.5;
btnUser.Opacity = 0.9; …Run Code Online (Sandbox Code Playgroud)