如何在 RightCenter 位置对齐文本 75 我曾尝试过 Amt.setGravity(Gravity.END); 和 Amt.setGravity(Gravity.RIGHT); 但它仍然右上角对齐我已经完成了
final EditText Amt = new EditText(this);
Amt.setId(20);
Amt.setText("");
Amt.setTextColor(Color.BLACK);
Amt.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
Amt.setHint("Amount");
Amt.setPadding(8,8,8,8);
Amt.setSingleLine(false);
Amt.setLines(1);
Amt.setBackgroundResource(R.drawable.text_bg);
Amt.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
Amt.setGravity(Gravity.END);
TourExpenseListDetailRow.addView(Amt);// add the column to the table row here
LinearLayout.LayoutParams params2 = (LinearLayout.LayoutParams)Amt.getLayoutParams();
params2.setMargins(0, 0, 5, 0); //substitute parameters for left, top, right, bottom
params2.gravity = Gravity.RIGHT;
Amt.setLayoutParams(params2);