在这里我看不出动画。加载程序时必须实现动画,以及单个屏幕状态的动画过渡,如何实现此帮助? enter image description here
答案 0 :(得分:1)
这是一个简单的加载动画。是您需要的吗?
自定义一个 ShowLoading.cs 界面:
public interface ShowLoading
{
void Show();
void Hide();
}
然后在 .Android MainActivity.cs 中实现该接口:
[assembly: Dependency(typeof(MainActivity))]
namespace App18.Droid
{
[Activity(Label = "App18", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity,ShowLoading
{
private static Dialog _dialog;
public void Hide()
{
_dialog.Dismiss();
}
public void Show()
{
_dialog.Show();
}
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
init();
}
private void init()
{
View view = LayoutInflater.From(this).Inflate(Resource.Layout.loading_layout,null);
_dialog = new Dialog(this);
_dialog.RequestWindowFeature((int)WindowFeatures.NoTitle);
_dialog.SetCancelable(false);
_dialog.SetContentView(view);
}
}
}
loading_layout.axml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frame"
>
<ProgressBar
android:id="@+id/loading"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerInParent = "true"
android:indeterminateBehavior="repeat"
android:indeterminateDrawable="@drawable/loading" />
</RelativeLayout>
loading.xml (在资源/可绘制对象中):
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/loadingicon"
android:fromDegrees="0.0"
android:pivotX="50.0%"
android:pivotY="50.0%"
android:toDegrees="360.0" />
您可以在页面中通过 DependencyService 对其进行调用,如下所示:
//show the loadig animation
DependencyService.Get<ShowLoading>().Show();
//hide it
DependencyService.Get<ShowLoading>().Hide();
答案 1 :(得分:0)
如果您正在使用Xamarin,请查看SkiaSharp。您可以创建矢量图形并对其进行动画设置。