EditText文本对齐方式

时间:2013-05-27 06:32:15

标签: android android-edittext

enter image description here

如何在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);

2 个答案:

答案 0 :(得分:1)

Amt.setGravity(Gravity.END);

上使用center 编辑,像这样:

button.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);

答案 1 :(得分:-3)

CSS中的

是“line-height:pixel”