如何在Dialog Android中添加移动进度微调器

时间:2018-01-22 12:49:56

标签: android dialog

我想把一个微调器放在android中的自定义对话框中,但它没有动画,任何知道原因的人。

Dialog dialog = new Dialog(this,R.style.mydialog);
dialog.setContentView(R.layout.dialog);
dialog.show();

下面粘贴了dialog.xml:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="center">
        <ProgressBar
            android:layout_width="@dimen/progressbar_width"
            android:layout_height="@dimen/progressbar_height"
            android:layout_marginTop="@dimen/progressbar_margin"
            android:layout_marginBottom="@dimen/progressbar_margin"
            android:indeterminateTint="@color/light_blue"
            android:indeterminateTintMode="src_atop"
            />
        <TextView
            android:id="@+id/dialog_loading_message"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/progressbar_margin"
            android:gravity="center"
            android:textColor="@android:color/white"
            android:textSize="@dimen/progressbar_message_text_size"
            android:visibility="gone"
            />
    </LinearLayout>
旋转器根本没有动画: static spinner

1 个答案:

答案 0 :(得分:0)

尝试以下代码,这将对您有所帮助:

if (dialog == null) {
        dialog = new Dialog(this);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        dialog.setContentView(R.layout.dialog);

    }
    RotateAnimation rotate = new RotateAnimation(0, 360,
            Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
            0.5f);
    rotate.setDuration(2000);
    rotate.setRepeatCount(Animation.INFINITE);
    dialog.findViewById(R.id.ivProgress).setAnimation(rotate);
    dialog.show();