简体   繁体   English

如何在Android中的线性布局的所需位置动态地向线性布局添加edittext

[英]how to add edittext to a linearlayout dynamically at desired positions to the linearlayout in android

I am new to android ,Actually i want to add edittexts to a relativelayout or linearlayout at desired positions on the layout .plz suggest me. 我是android的新手,实际上我想将edittexts添加到相对布局或linearlayout的布局上的期望位置。plz建议我。 thanks in advance.. 提前致谢..

Do you really need add an EditText programmatically? 您是否真的需要以编程方式添加EditText?

Usually it is enough to hide certain Views and change the visibility programmatically. 通常,隐藏某些视图并以编程方式更改可见性就足够了。

<EditText android:id="@+id/view_name"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:visibility="gone"
        />

The three values for visibility are "visible", "invisible" and "gone". 可见性的三个值是“可见”,“不可见”和“消失”。 "gone" means the EditText is taking no space. “消失”表示EditText不占空间。 "invisible" means that the space it would take is empty. “不可见”表示它将占用的空间为空。

You can change the visibility the following way: 您可以通过以下方式更改可见性:

EditText editText = (EditText) findViewById(R.id.view_name);
editText.setVisibility(View.VISIBLE);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM