【问题标题】:Progress Dialog over partial screen部分屏幕上的进度对话框
【发布时间】:2017-07-04 06:20:54
【问题描述】:

我有一个包含三个标签的片段。在其中一个选项卡上,我有一个对话框,当后台同步进行时会旋转。但是当后台同步正在进行时,我需要能够继续处理其他部分。

我目前使用dialog.setCancelable(false) 退出对话框,以便我可以使用应用程序的其余部分。但这给了我在同步进行的片段上的情绪屏幕。

有没有什么办法让对话框只覆盖在屏幕的一部分上(只覆盖同步进行的片段)?换句话说,一个不占用整个屏幕的对话框,以便我可以在不取消对话框的情况下移动到其他选项卡?

java代码中对话框的实现:

    dialog = new Dialog(getActivity());
    dialog.requestWindowFeature(Window.FEATURE_PROGRESS);
    dialog.setCancelable(true);
    dialog.setContentView(R.layout.dialog_progress_bar);
    dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);

dialog.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ProgressBar
        android:id="@+id/dialogProgressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"/>

</LinearLayout>

【问题讨论】:

  • 为什么不在fragmnet 的xml 中直接使用progressBar 而不是在Dialog 中显示它?
  • 是的,它有效。谢谢

标签: android android-fragments progressdialog


【解决方案1】:

不,您无法使用Dialog 实现此行为。

#. 由于您正在使用Fragment 并希望显示同步的progress,所以我认为您可以在片段layout XML 中添加ProgressBar 而不是使用@ 987654328@ 并根据sync 状态显示/隐藏ProgressBar

状态:

  1. 当同步为going on 时,仅显示ProgressBar 而隐藏其他Views
  2. 同步completed时,隐藏ProgressBar并根据您的需要向其他人显示Views

#. 您还可以在 Fragment layout XML 中使用 SwipeRefreshLayout 来显示进度正在进行中。当sync 正在进行时,它将show 循环ProgressBar,当sync 完成时,它会自动hide

这里有一个很好的教程:Android Swipe Down to Refresh ListView Tutorial

希望对你有帮助~

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-09
    • 1970-01-01
    • 2013-11-08
    • 1970-01-01
    • 2017-01-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多