我創建了一個alertDialog來請求登錄數據。wrap_content,fill_parent
我想用所有的橫向空間,但我不能得到它:
AlertDialog.Builder loginData = new AlertDialog.Builder(activity);
loginData.setTitle("Tus datos");
LinearLayout layout = new LinearLayout(activity);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
LinearLayout linea1 = new LinearLayout(activity);
linea1.setOrientation(LinearLayout.HORIZONTAL);
linea1.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
final TextView Usuario = new TextView(activity);
Usuario.setText("Usuario");
linea1.addView(Usuario);
final EditText usuario = new EditText(activity);
linea1.addView(usuario);
layout.addView(linea1);
// Set an EditText view to get user input
LinearLayout linea2 = new LinearLayout(activity);
linea2.setOrientation(LinearLayout.HORIZONTAL);
linea2.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
final TextView Contrasena = new TextView(activity);
Contrasena.setText("Contraseña");
linea2.addView(Contrasena);
final EditText contrasena = new EditText(activity);
linea2.addView(contrasena);
layout.addView(linea2);
loginData.setView(layout);
loginData.setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
try{
//do the work
} catch (Exception e){
e.printStackTrace();
}
}
});
loginData.show();
}
我該怎麼辦呢?
它工作完美! 非常感謝你! – user1256477 2012-03-20 11:06:09