我试着做了个小应用。我有一个progressBar和一个按钮。当我点击我的按钮时,它会在我的progressBar上开始倒计时30秒。它可以在我所有的模拟器android手机上运行,除了那部手机:
三星盖乐世j5 pro (安卓8.0) HTC One M8 (安卓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());
}
}
}
}
发布于 2019-02-19 03:52:20
最好的方法是使用MVVM。在可能的情况下,此代码不起作用
https://stackoverflow.com/questions/54753199
复制相似问题