当手机需要从网络服务中检索一些数据时,我正在制作一个覆盖在屏幕上的对话框,问题是它的表现真的很奇怪:
为什么不将imageView
(宽度和高度设置为** fill_parent )** 填充分配给警报的整个空间?
以下是显示警报的代码:
public class WaitDialog {
private static AlertDialog dialog;
public static void show(Activity pariente) {
WindowManager.LayoutParams sizeParams = new WindowManager.LayoutParams();
parametrosTamano.height = 128;
parametrosTamano.width = 128;
LayoutInflater inflater = (LayoutInflater)pariente.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View content = inflater.inflate(R.layout.waitingdialog, null);
ImageView animation = (ImageView)contenido.findViewById(R.id.waitpic);
animacion.startAnimation(AnimationUtils.loadAnimation(pariente, R.anim.animacionespera));
AlertDialog.Builder builder = new AlertDialog.Builder(pariente);
builder.setView(content);
builder.setCancelable(false);
dialog = constructor.create();
dialog.show();
//sizeParams.copyFrom(dialog.getWindow().getAttributes());
dialog.getWindow().setAttributes(sizeParams);
//dialog.getWindow().setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
}
public static void hide() {
dialog.hide();
dialog.dismiss();
dialog = null;
}
}
这是夸大的XML:
<ImageView
android:id="@+id/imagenEspera"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:src="@drawable/animespera"
android:scaleType="fitXY"
android:layout_centerInParent="true"
android:contentDescription="@string/espera"/>
我做错了吗?有更好的方法吗?
注意:有人可以解决上面的问题吗?
答案 0 :(得分:1)
Hello Drknezz,
Please make the Layout for showing Alert and through Layout inflater show the alert. Like this
final Dialog _contiDialog=new Dialog(Qualify2.this,android.R.style.Theme_Translucent_NoTitleBar);
_contiDialog.setContentView(R.layout.continuedilog);
continuedilog.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit Your Score"
android:textStyle="bold"
android:paddingTop="10dip"
android:textColor="#000"/>
<LinearLayout
android:gravity="center"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:paddingTop="10dip"
android:orientation="vertical">
<RelativeLayout
android:paddingLeft="20dip"
android:paddingRight="20dip"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<TextView android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/TextView01"
android:textColor="#000"
android:text="Initial:"
android:layout_alignParentLeft="true"
android:textStyle="bold"/>
<EditText
android:layout_width="150dip"
android:layout_height="35dip"
android:id="@+id/initials"
android:layout_alignParentRight="true"
android:textSize="12dip"
android:singleLine="true" />
</RelativeLayout>
<RelativeLayout
android:gravity="center_horizontal|center_vertical"
android:paddingLeft="20dip"
android:paddingRight="20dip"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<TextView android:id="@+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:textStyle="bold"
android:layout_alignParentLeft="true"
android:text="Email: "/>
<EditText
android:id="@+id/emails"
android:layout_width="150dip"
android:layout_height="35dip"
android:singleLine="true"
android:layout_alignParentRight="true"
android:textSize="12dip"/>
</RelativeLayout>
<RelativeLayout
android:gravity="center_horizontal|center_vertical"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:paddingLeft="20dip"
android:paddingRight="20dip">
<TextView android:id="@+id/TextView04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/TextView03"
android:textColor="#000"
android:text="Smartphone:"
android:layout_alignParentLeft="true"
android:textStyle="bold"/>
<Spinner android:prompt="@string/planet_prompt"
android:id="@+id/smart_phone"
android:layout_width="150dip"
android:layout_height="35dip"
android:layout_alignParentRight="true"
android:layout_below="@+id/emails"/>
</RelativeLayout>
<RelativeLayout
android:gravity="center_horizontal|center_vertical"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:paddingLeft="20dip"
android:paddingRight="20dip">
<TextView android:id="@+id/TextView05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:text="Country: "
android:layout_alignParentLeft="true"
android:textStyle="bold"/>
<Spinner android:prompt="@string/planet_prompt1"
android:id="@+id/country"
android:layout_width="150dip"
android:layout_alignParentRight="true"
android:layout_height="35dip"/>
</RelativeLayout>
<CheckBox android:id="@+id/term1" android:layout_width="wrap_content"
android:background="@drawable/checkbox_background"
android:button="@drawable/checkbox"
android:text="I accept the Terms and Conditions of this service. I know I will be sending my initials,email address, my handset model details,and my score to QuickNimble."
android:textColor="#000"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_marginLeft="9dip"></CheckBox>
<TextView android:layout_width="wrap_content"
android:layout_height="10dip"/>
<CheckBox android:id="@+id/term2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/checkbox_background"
android:button="@drawable/checkbox"
android:text="I would like to receive more information and offers from QuickNimble."
android:textColor="#000"
android:textSize="12sp"
android:layout_marginLeft="9dip"/>