0
我有Android的EditText小部件的問題。在代碼中,我設置了按像素的寬度。但是,當用戶關注並嘗試輸入文本時,editText小部件會發生更改。我們如何解決這個問題? 請參閱視頻以瞭解我的問題。 VIDEOAndroid EditText寬度變化
注意:不需要使用錯誤。如果你有些不明白,請在這裏提問,並提供更多細節。謝謝。
float[] sizes = calculateMaxWidthAnswer(answer);
this.editTextWidth = sizes[0];
this.editTextHeight = sizes[1];
editText.setWidth((int) editTextWidth);
editText.setHeight((int) editTextHeight);
protected float[] calculateMaxWidthAnswer(String item) {
CustomKeyboardEditText cKE = new CustomKeyboardEditText(getContext(), isDisabledCustomKeyboard);
cKE.setSingleLine(true);
cKE.setTypeface(Typeface.DEFAULT_BOLD);
cKE.setText(item);
Paint mPaint = cKE.getPaint();
Rect bounds = new Rect();
mPaint.getTextBounds(item, 0, item.length(), bounds);
float size = bounds.width() + MathTool.dpToPx(cKE.PADDING_LR * 3);
return new float[]{size, bounds.height()};
}
在CustomKeyboardEditText
小部件,任何代碼,它可以使這個麻煩。
你能告訴我們一些代碼嗎? – MeLine
@MeLine更新 –
如果我想改變一個視圖的寬度,我會使用view.getLayoutParams()。Width = ... – Nanoc