如何在 Android 中以编程方式设置 EditText 框的高度和宽度 [英] How to set EditText box height and width programmatically in Android

查看:19
本文介绍了如何在 Android 中以编程方式设置 EditText 框的高度和宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 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 EditTexts 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 框的高度和宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆