本文介紹了如何在 Android 中以編程方式設置 EditText 框的高度和寬度的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我想在 Android 中以編程方式管理 EditText
框的高度和寬度.我嘗試了 edittext.setWidth(32);
和 edittext.setEms(50);
,但兩者都不起作用.請參閱下面的代碼,因為我正在使用它在 Android 中創建動態 EditText
.
I want to manage the height and width of an EditText
box programmatically in Android. I tried edittext.setWidth(32);
and edittext.setEms(50);
, but both are not working. See my below code, as I am using it to create dynamic EditText
s in Android.
private EditText createEditText()
{
final LayoutParams lparams = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
final EditText edittext = new EditText(this);
edittext.setLayoutParams(lparams);
edittext.setWidth(32);
edittext.setEms(50);
return edittext;
}
推薦答案
private EditText createEditText()
{
final LayoutParams lparams = new LayoutParams(50,30); // Width , height
final EditText edittext = new EditText(this);
edittext.setLayoutParams(lparams);
return edittext;
}
試試這個.
這篇關于如何在 Android 中以編程方式設置 EditText 框的高度和寬度的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!