小米视频加载进度条效果实现

  好吧,其实这些都是我闲暇时自己做着玩的,以前总是拿来主义,现在分享一下让我也为大家做一点贡献好了。废话不说了,看效果。

好吧 其实没什么技术含量 直接上代码好了 和我上一篇利用WPF动画实现圆形进度条是一个道理,表现形式不同而已。

 1 <UserControl x:Class="MyUserControlLibrary.CircleProgressbarcontrol"
 2              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 5              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 6              xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing"
 7              xmlns:local ="clr-namespace:MyUserControlLibrary"
 8              mc:Ignorable="d"
 9              d:DesignHeight="60" d:DesignWidth="60" MinWidth="60" MinHeight="60" Loaded="UserControl_Loaded">
10     <UserControl.Resources>
11         <local:ConverterCircleToPercent x:Key="converter"/>
12         <Storyboard x:Key="MainStoryboard">
13             <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(ed:Arc.EndAngle)" Storyboard.TargetName="ProgressArea">
14                 <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
15                 <EasingDoubleKeyFrame KeyTime="0:0:0.05" Value="360"/>
16             </DoubleAnimationUsingKeyFrames>
17         </Storyboard>
18     </UserControl.Resources>
19     <Grid>
20         <Border Name="MainBorder" Margin="0,0,0,0" CornerRadius="500" BorderThickness="2" BorderBrush="White" Opacity="0.6" Background="Black"/>
21         <ed:Arc Name="ProgressArea" Margin="5,5,5,5" ArcThickness="1" StartAngle="0" EndAngle="0" ArcThicknessUnit="Percent" Stretch="None" Fill="White" Opacity="0.4"/>
22         <Ellipse Name="CenterCircle" Width="5" Height="5" Fill="White" Opacity="0.7"/>
23         <Label Name="AreaShow" Margin="10,10,10,10" Content="{Binding ElementName=ProgressArea, Path=EndAngle,Converter={StaticResource converter}}" Foreground="White" FontFamily="宋体" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="20" Opacity="0.8"/>
24     </Grid>
25 </UserControl>

XMAL前端

  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Text;
  5 using System.Windows;
  6 using System.Windows.Controls;
  7 using System.Windows.Data;
  8 using System.Windows.Documents;
  9 using System.Windows.Input;
 10 using System.Windows.Media;
 11 using System.Windows.Media.Animation;
 12 using System.Windows.Media.Imaging;
 13 using System.Windows.Navigation;
 14 using System.Windows.Shapes;
 15
 16 namespace MyUserControlLibrary
 17 {
 18     /// <summary>
 19     /// CircleProgressbarcontrol.xaml 的交互逻辑
 20     /// </summary>
 21     public partial class CircleProgressbarcontrol : UserControl
 22     {
 23         #region 属性
 24
 25         private bool isShowPercent = true;
 26         /// <summary>
 27         /// 是否显示百分比
 28         /// </summary>
 29         [System.ComponentModel.Browsable(true),System.ComponentModel.Category("Appearance"),System.ComponentModel.Description("获取或设置是否显示百分比")]
 30         public bool IsShowPercent {
 31             get {
 32                 return isShowPercent;
 33             }
 34             set {
 35                 isShowPercent = value;
 36                 if (isShowPercent)
 37                 {
 38                     AreaShow.Visibility = System.Windows.Visibility.Visible;
 39                 }
 40                 else {
 41                     AreaShow.Visibility = System.Windows.Visibility.Hidden;
 42                 }
 43             }
 44         }
 45
 46         private TimeSpan percentTimeSpan = new TimeSpan(0, 0, 1);
 47         /// <summary>
 48         /// 每次更新百分比时的经过时间
 49         /// </summary>
 50         [System.ComponentModel.Browsable(true),System.ComponentModel.Category("Appearance"),System.ComponentModel.Description("获取或设置每次更新百分比时的经过时间")]
 51         public TimeSpan PercentTimeSpan {
 52             get {
 53                 return percentTimeSpan;
 54             }
 55             set {
 56                 percentTimeSpan = value;
 57                 Storyboard sb = (Storyboard)this.Resources["MainStoryboard"];
 58                 ((DoubleAnimationUsingKeyFrames)sb.Children[0]).KeyFrames[1].KeyTime = KeyTime.FromTimeSpan(value);
 59             }
 60         }
 61
 62         #endregion
 63
 64         public CircleProgressbarcontrol()
 65         {
 66             InitializeComponent();
 67         }
 68
 69         #region 方法
 70
 71         /// <summary>
 72         /// 设置当前百分比
 73         /// </summary>
 74         /// <param name="d">百分比</param>
 75         public void setPercent(double d) {
 76             Storyboard sb = (Storyboard)this.Resources["MainStoryboard"];
 77             ((DoubleAnimationUsingKeyFrames)sb.Children[0]).KeyFrames[0].Value = ProgressArea.EndAngle;
 78             ((DoubleAnimationUsingKeyFrames)sb.Children[0]).KeyFrames[1].Value = d*3.6;
 79             sb.Begin();
 80         }
 81
 82         #endregion
 83
 84         #region 事件
 85
 86         //界面调整
 87         private void UserControl_Loaded(object sender, RoutedEventArgs e)
 88         {
 89             if (Double.IsNaN(Width))
 90             {
 91                 if (ActualWidth >= ActualHeight)
 92                 {
 93                     double t = (ActualWidth - ActualHeight) / 2;
 94                     MainBorder.Margin = new Thickness(t, 0, t, 0);
 95                     ProgressArea.Margin = new Thickness(t + 5, 5, t + 5, 5);
 96                     AreaShow.Margin = new Thickness(t + 10, 10, t + 10, 10);
 97                 }
 98                 else
 99                 {
100                     double t = (ActualHeight - ActualWidth) / 2;
101                     MainBorder.Margin = new Thickness(0, t + 0, 0, t + 0);
102                     ProgressArea.Margin = new Thickness(5, t + 5, 5, t + 5);
103                     AreaShow.Margin = new Thickness(10, t + 10, 10, t + 10);
104                 }
105                 AreaShow.FontSize = AreaShow.ActualWidth / 2;
106             }
107             else
108             {
109                 if (Width >= Height)
110                 {
111                     double t = (Width - Height) / 2;
112                     MainBorder.Margin = new Thickness(t, 0, t, 0);
113                     ProgressArea.Margin = new Thickness(t + 5, 5, t + 5, 5);
114                     AreaShow.Margin = new Thickness(t + 10, 10, t + 10, 10);
115                 }
116                 else
117                 {
118                     double t = (Height - Width) / 2;
119                     MainBorder.Margin = new Thickness(0, t, 0, t);
120                     ProgressArea.Margin = new Thickness(5, t + 5, 5, t + 5);
121                     AreaShow.Margin = new Thickness(10, t + 10, 10, t + 10);
122                 }
123                 AreaShow.FontSize = AreaShow.ActualWidth / 2;
124             }
125         }
126
127         #endregion
128     }
129 }

后台代码

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Globalization;
 4 using System.Linq;
 5 using System.Text;
 6 using System.Windows.Data;
 7
 8 namespace MyUserControlLibrary
 9 {
10     /// <summary>
11     /// 将角度转化成百分比
12     /// </summary>
13     public class ConverterCircleToPercent:IValueConverter
14     {
15         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
16         {
17             return (int)(double.Parse(value.ToString()) * 10 / 36);
18         }
19         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
20         {
21             throw new NullReferenceException();
22         }
23     }
24 }

转换器

时间: 2024-08-09 02:08:04

小米视频加载进度条效果实现的相关文章

可爱!带有数字显示的加载进度条效果插件

可爱!带有数字显示的加载进度条效果插件 有的时候,在我们的应用程序中,我们希望能够显示特定任务的百分比进度.这里分享的这款小巧的 JavaScript 插件就是实现这个功能,易于使用和定制,而且是是免费开源的. 立即下载      在线演示 有的时候,在我们的应用程序中,我们希望能够显示特定任务的百分比进度.这里分享的这款小巧的 JavaScript 插件就是实现这个功能,易于使用和定制,而且是是免费开源的. 关键字:可爱!带有数字显示的加载进度条效果插件 下载地址:https://github

ajax页面加载进度条插件

下面两个都是youtube视频的加载进度条效果的ajax插件 一.官网:http://ricostacruz.com/nprogress/官网 github:https://github.com/rstacruz/nprogress/ 二.http://www.onextrapixel.com/2013/09/02/loadingbar-js-adding-a-youtube-like-loading-bar-to-your-website/

网页加载进度条的实现

本次主要介绍一下网页加载进度的实现.如下图,在页面加载的时候,上方红色的进度条 网页加载进度的好处是能够更好的反应当前网页的加载进度情况,loading进度条可用动画的形式从开始0%到100%完成网页加载这一过程.但是目前的浏览器并没有提供页面加载进度方面的接口,也就是说页面还无法准确返回页面实际加载的进度,本文中我们使用jQuery来实现页面加载进度条效果. 首先我们要知道的是,目前没有任何浏览器可以直接获取正在加载对象的大小.所以我们无法通过数据大小来实现0-100%的加载显示过程. 因此我

缓冲进度条或加载进度条

缓冲进度条或加载进度条,在加载页面或者视频加载过程中,为了做到更好的UI及App功能体验交互,这些缓冲加载的等待效果是必不可少的: 下面来看一下旋转的动画效果:那么,他们的具体源码在这里:loading_1: <?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" andro

给WebView添加漂亮的加载进度条

为了增强用户体验,所有在WebView头部给加了个进度条,看起来不错哦. 布局XMl:activity_main.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent&q

网站顶部显示预加载进度条preload.js

网站加载的速度快的话,不会显示进度条加载时候的样式. 支持性主流浏览器都支持,ie浏览器需要9以上9也支持. 使用方法 <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <script src="js/preload.js"></script> <script type="text/javascript">

【Web前沿技术】纯 CSS3 打造的10个精美加载进度条动画

之前向大家介绍8款优秀的 jQuery 加载动画和进度条插件,今天这篇文章向大家推荐10个纯 CSS3 代码实现精美加载进度条动画效果的方案.加载动画和进度条在网站和 Web 应用中的使用非常流行,特别是在使用 Ajax 技术加载内容的应用场景中,使用时尚的加载动画和进度条告诉用户内容正在加载中是一种非常友好的方式. 您可能感兴趣的相关文章 20个非常绚丽的 CSS3 特性应用演示 23个纯 CSS3 打造的精美LOGO图案 35个让人惊讶的 CSS3 动画效果演示 推荐12个漂亮的 CSS3

你没见过吧?16款形态各异的加载进度条设计

互联网连接越来越快,但难免有一些时刻需要我们等待.在这种情况下,创意的设计师尽力减轻用户等待的痛苦,苦思敏想设计各种创意的进度条(或加载条)效果 ,让用户等待的过程变得更加愉悦. 您可能感兴趣的相关文章 22套 Web & Mobile PSD 用户界面素材 45套精美的手机界面设计素材和设计工具 分享30套精美的Web和手机开发UI素材 60个精美的免费移动开发PSD素材资源 45套新鲜出炉的精美 PSD 网页设计素材 Loading by pearlsomani Flat Loading B

HTML5 CSS3 诱人的实例 : 网页加载进度条的实现,下载进度条等

今天给大家带来一个比较炫的进度条,进度条在一耗时操作上给用户一个比较好的体验,不会让用户觉得在盲目等待,对于没有进度条的长时间等待,用户会任务死机了,毫不犹豫的关掉应用:一般用于下载任务,删除大量任务,网页加载等:如果有使用html5为手机布局的,也可以用于手机中~ 效果图: 1.html结构: <div id="loadBar01" class="loadBar"> <div> <span class="percent&qu