0

我正在使用 MVVMCross 开发一个 Android 应用程序。我在 AXML 上使用进度条标签,只要应用程序有后台活动,它就会停止动画。我想这是因为我以错误的方式使用同步任务,但我找不到解决它的方法。

我使用的 ProgressBar 标签是:

<LinearLayout
  android:orientation="vertical"
  android:background="#88000000"
  android:layout_alignParentTop="true"
  local:MvxBind="Visibility Visibility(IsLoading)"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:gravity="center_vertical|center_horizontal">
  <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:id="@+id/progressBar1"
        android:layout_marginTop="@dimen/element_margin_large"
        android:layout_marginBottom="@dimen/element_margin_large" />
</LinearLayout>

我尝试更改IsLoadingtrue, 以使其始终可见,并且每次应用程序执行任何后退过程时动画都会停止。

编辑:我在 viewmodel 上尝试的代码是这样的:

private MvxCommand _xxxCommand;
        public ICommand XxxCommand
        {
            get
            {
                _xxxCommand = _xxxCommand ?? new MvxCommand(XxxCmd);
                return _xxxCommand;
            }
        }

public async void XxxCmd()
        {
            IsLoading = true;
            await Task.Run(() =>
            {          
            ShowViewModel<XxxViewModel>();
            });
            IsLoading = false;
        } 

但它在ShowViewModel执行时一直冻结。在下一个视图中,我有一些绑定和对 external 的调用API,但它们都是asyncawaited

感谢您的关注。

4

1 回答 1

0

问题不在于 UI 本身,而是正如您自己所说,您正在使用正在执行的同步代码阻塞 UI 线程。

您需要使用 ThreadPool 或 Task 来封装您所做的事情并在后台运行它们,而不是占用 UI 线程的时间。

具体实现将取决于您的代码,您在开篇文章中没有提供这些代码。

于 2016-07-08T12:44:18.007 回答