开发者

How to make single-line EditText draw itself correctly when using a specific size

I need to set the height and width of a EditText widget programmatically. I am using a RelativeLayout to do this, and it works fine as far as the size goes, but the actual widget paints itself incorrectly:

How to make single-line EditText draw itself correctly when using a specific size

I would have expected it to paint like this (which it will if I set the height to ViewGroup.LayoutParams.WRAP_CONTENT instead of my requested height - sometimes):

How to make single-line EditText draw itself correctly when using a specific size

Any ideas?

Please note that I can't switch to DIP:s (dpi independence is actually already handled by the engine that use this code). Also note that I haven't found any value of setTextS开发者_如何学Goize() that fix the misbehaviour.

This is how I create my widget:

  EditText et = new EditText(this);
  et.setFocusable(true);
  et.setSingleLine(true);
  et.setHint(label);
  et.setText(text);
  et.setTextSize(TypedValue.COMPLEX_UNIT_PX,(h/3)+5);
  et.setId(cn); 
  rllp = new RelativeLayout.LayoutParams(w,h);
  rllp.leftMargin = x;
  rllp.topMargin = y;
  layout.addView(et,rllp);


try to change the last line of the posted code to this

layout.addView(et);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜