【问题标题】:Create progress dialog with another layout使用另一个布局创建进度对话框
【发布时间】:2013-03-04 07:51:21
【问题描述】:

我想创建一个扩展另一个 XML 文件的进度对话框。

所以我尝试了以下代码

public class MyProgressDialog extends AlertDialog {

        public MyProgressDialog(Context context) {
            super(context,R.layout.customprog);

            // TODO Auto-generated constructor stub
        }

    }
MyProgressDialog pdia=new MyProgressDialog(this);

并且在 asynctask 中使用 pdia.show(); 在 onPreExecute() 中显示这一点

porgspin.xml

<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/progress1"
android:pivotX="50%"
android:pivotY="50%" />

customprog.xml

<RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="80dp"
        android:padding="10dp" >

        <ProgressBar
            android:id="@+id/imageView1"
            android:indeterminateDrawable="@drawable/porgspin"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:src="@drawable/progress" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="41dp"
            android:layout_toRightOf="@+id/imageView1"
            android:text="Loading..."
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000000" />

    </RelativeLayout>

当我运行程序时,我无法查看进度条。

我在这里错过了什么?

【问题讨论】:

    标签: android android-layout progressdialog


    【解决方案1】:

    super(context,R.layout.customprog) 的第二个参数接受 theme 资源而不是 layout。你为什么不增加布局呢?

    public class MyProgressDialog extends AlertDialog 
    {
    
           @Override
           public void show() {
    
            super.show();
            setContentView(R.layout.activity_main);
           }
    
    }
    

    【讨论】:

    • 如果代码在 Lollipop 下运行,则必须传递 Theme 对象
    【解决方案2】:

    不要在构造函数中传递您的自定义布局,而是覆盖对话框的 onCreate() 方法并使用 setContentView() 方法来传递您的自定义布局..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-15
      相关资源
      最近更新 更多