首页 > 解决方案 > 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());
             }
        }
    }
 }

标签: androidxamarin.formsprogress-bar

解决方案


最好的方法是使用 MVVM。在可能的情况下,此代码不起作用


推荐阅读