什麼,我試圖做的是Android定製對話框,在這裏它是在圖片:我如何解決自定義對話框中的對齊問題?
正如你可以看到有高度之間有很大的空間,這是編輯的文本,如何可以使第二排的所有組件都在左邊或水平居中,這裏是我的代碼:
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(FullImageActivity2.this);
final TextView title = new TextView(FullImageActivity2.this);
title.setTextColor(Color.parseColor("#000000"));
title.setText("Add To Cart");
title.setPadding(5, 10, 0, 10);
alertDialogBuilder.setCustomTitle(title);
LinearLayout ll=new LinearLayout(FullImageActivity2.this);
final LayoutParams lparams = new LayoutParams(50,50);
lparams.weight=(float) 0.25;
lparams.leftMargin=3;
lparams.rightMargin=3;
ll.setOrientation(LinearLayout.VERTICAL);
TableLayout table = new TableLayout (FullImageActivity2.this);
TableRow row0= new TableRow(FullImageActivity2.this);
TableRow row1= new TableRow(FullImageActivity2.this);
TableRow.LayoutParams tr1 = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT);
tr1.gravity=1;
//tr1.topMargin=15;
//tr1.bottomMargin=10;
row1.setLayoutParams(tr1);
row0.setLayoutParams(tr1);
final EditText height = new EditText(FullImageActivity2.this);
final TextView heightTxt = new TextView(FullImageActivity2.this);
final EditText width = new EditText(FullImageActivity2.this);
final TextView widthTxt = new TextView(FullImageActivity2.this);
final TextView hint = new TextView(FullImageActivity2.this);
height.setInputType(InputType.TYPE_CLASS_NUMBER);
height.setLayoutParams(lparams);
width.setInputType(InputType.TYPE_CLASS_NUMBER);
//height.setPadding(3, 0, 3, 0);
width.setLayoutParams(lparams);
heightTxt.setText("height");
heightTxt.setTextColor(Color.parseColor("#000000"));
heightTxt.setPadding(7, 0, 5, 0);
hint.setText("please enter height and width in meter");
hint.setTextColor(Color.parseColor("#000000"));
hint.setPadding(5, 0, 5, 0);
widthTxt.setText("width");
widthTxt.setTextColor(Color.parseColor("#000000"));
widthTxt.setPadding(5, 0, 5, 0);
row0.addView(hint);
row1.addView(heightTxt);
row1.addView(height);
row1.addView(widthTxt);
row1.addView(width);
table.addView(row0);
table.addView(row1);
// ll.addView(height);
//ll.addView(heightTxt);
ll.addView(table);
alertDialogBuilder.setView(ll);
alertDialogBuilder
.setCancelable(false)
.setPositiveButton("Cancel",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
}
})
.setNegativeButton("Add",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
itemId=productname.getText().toString();
Height= height.getText().toString();
Width= width.getText().toString();
Image=imageForCart;
Log.e("item id",itemId+"");
Log.e("Height",Height+"");
Log.e("Width",Width+"");
Log.e("Image",Image+"");
AddToCart.add_to_class(itemId,Height,Width,Image);
Toast.makeText(FullImageActivity2.this,"add successfully" , Toast.LENGTH_SHORT).show();
Intent opencart=new Intent(FullImageActivity2.this,CartList.class);
startActivity(opencart);
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
任何幫助?
它沒有工作..! – sereen 2014-09-03 11:09:59