300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > Xamarin.Android 实现正在加载动画效果

Xamarin.Android 实现正在加载动画效果

时间:2018-12-16 07:31:15

相关推荐

Xamarin.Android 实现正在加载动画效果

通过添加不同帧数的图片,来实现自己想要的动画效果正在加载。。。

第一步: Resources/drawable 目录下添加每一帧的图片,我设定了18帧

第二步:实现动画效果,drawable下新建页面 loading_anim.xml

<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="/apk/res/android" android:oneshot="false" > <item android:drawable="@drawable/load_img1" android:duration="150"/> <item android:drawable="@drawable/load_img2" android:duration="150"/><item android:drawable="@drawable/load_img3" android:duration="150"/><item android:drawable="@drawable/load_img4" android:duration="150"/><item android:drawable="@drawable/load_img5" android:duration="150"/><item android:drawable="@drawable/load_img6" android:duration="150"/><item android:drawable="@drawable/load_img7" android:duration="150"/><item android:drawable="@drawable/load_img8" android:duration="150"/><item android:drawable="@drawable/load_img9" android:duration="150"/><item android:drawable="@drawable/load_img10" android:duration="150"/><item android:drawable="@drawable/load_img11" android:duration="150"/><item android:drawable="@drawable/load_img12" android:duration="150"/><item android:drawable="@drawable/load_img13" android:duration="150"/><item android:drawable="@drawable/load_img14" android:duration="150"/><item android:drawable="@drawable/load_img15" android:duration="150"/><item android:drawable="@drawable/load_img16" android:duration="150"/><item android:drawable="@drawable/load_img17" android:duration="150"/><item android:drawable="@drawable/load_img18" android:duration="150"/></animation-list>

第三步:实现加载页半透明样式 values下新建界面style.xml

<?xml version="1.0" encoding="utf-8" ?><resources><style name="MyDialogStyle"><item name="android:windowBackground">@drawable/filled_box</item><item name="android:backgroundDimEnabled">false</item><item name="android:windowNoTitle">true</item><item name="android:windowIsTranslucent">false</item><item name="android:windowContentOverlay">@null</item><!--<item name="android:windowAnimationStyle">@style/dialog_animation</item>--><item name="android:colorBackgroundCacheHint">@null</item><item name="android:backgroundDimAmount">0.6</item> <!--灰度--></style></resources>

第四步:layout下新建加载界面loading.axml

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="/apk/res/android"xmlns:tools="/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"><RelativeLayoutandroid:layout_width="600dp"android:layout_height="500dp"><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="fill_parent"android:gravity="center"android:orientation="horizontal"><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/imageView1"android:background="@drawable/loading_anim" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="正在加载..."android:textColor="#fff"android:textSize="28sp"android:layout_marginLeft="10dp"android:id="@+id/txt_loading" /></LinearLayout></RelativeLayout></RelativeLayout>

第五步:点击事件下,弹出加载界面,完成

public void OnClick(View v){int id = v.Id;if (id == Resource.Id.btn_buy){Dialog dialog = new Dialog(this, Resource.Style.MyDialogStyle);dialog.SetContentView(Resource.Layout.loading);dialog.Show();mImageView = dialog.FindViewById<ImageView>(Resource.Id.imageView1);TextView tv=dialog.FindViewById<TextView>(Resource.Id.txt_loading);tv.Text = "正在加载,请稍后...";mAnimation = (AnimationDrawable)mImageView.Background;mImageView.Post(new Runnable(() =>{mAnimation.Start();}));new Handler().PostDelayed(new Runnable(() =>{//等待10000毫秒后销毁此页面,并提示登陆成功 dialog.Dismiss();//取消加载Toast.MakeText(this, "加载完成", ToastLength.Short).Show();}), 10000); }}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。