android - Xamarin 表单 Progressbar 方法 progressTo 在某些 Android 设备上不起作用
问题描述
我试着做一个小应用程序。我有一个进度条和一个按钮。当我点击我的按钮时,它会在我的进度条上开始倒计时 30 秒。它适用于我所有的模拟器 android 手机,除了那些手机:
-三星 Galaxy j5 pro (Android 8.0)
- HTC One M8 (Android 6.0)
在那些设备上,它会在不到 1 秒的时间内变为 0。
我发现了这个https://forums.xamarin.com/discussion/134407/progressbar-progressto-only-works-on-some-devices 但没有答案
这是我的 MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ProgressApp.MainPage">
<StackLayout>
<ProgressBar x:Name="progressBar" HeightRequest="20" Progress="1" HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand"/>
<Button Text="Start !"
FontSize="20"
HorizontalOptions="FillAndExpand"
BackgroundColor="#00b484"
TextColor="White"
FontAttributes="Bold"
Clicked="OnCommencerClicked" />
</StackLayout>
</ContentPage>
这是我的 MainPage.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace ProgressApp
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void OnCommencerClicked(object sender, EventArgs args)
{
try
{
progressBar.ProgressTo(0, 30000, Easing.Linear);
}
catch (System.Exception exc)
{
System.Diagnostics.Debug.WriteLine(exc.ToString());
}
}
}
}
解决方案
最好的方法是使用 MVVM。在可能的情况下,此代码不起作用
推荐阅读
- python-3.x - 使用 Boto3 将数字插入 DynamoDB 表
- instagram - 我们可以通过 webhook/api 从 Instagram 故事的响应中获得分享反应吗?
- attributeerror - 在 Pycharm 上安装 Behave
- python - 在python中显示正常数字
- flutter - 使用提供程序在 null 上调用了颤振添加方法
- mongodb - Mongoose:如何批量查询模型的数组类型字段
- javascript - 在日历显示时自动设置开始日期并启用结束日期的日期选择(daterangepicker)
- xamarin.forms - xamarin.forms 找出设置为 imagesource 的图片
- javascript - API 无响应
- ios - 跨 iOS 版本填充数据时,数据构造函数具有不同的语义