Dynamiclly使用现有的TextView布局参数添加一个TextView [英] Dynamiclly add a textview using existing textview layout parameters

查看:247
本文介绍了Dynamiclly使用现有的TextView布局参数添加一个TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从活动添加一个TextView当按钮已经pssed $ P $。我已经找到了如何从活动增加但不是编码所需的布局参数的新的TextView,是有可能在现有textviews参数(在XML布局)复制到新的TextView?

I am trying to add a TextView from the activity when a button has been pressed. I have found how to add a new textview from the activity, however instead of coding the required layout parameters is it possible to copy an existing textviews parameters (in the xml layout) to the new textview?

我曾尝试:
        TextView的TV1 =新的TextView(本);
        TextView中TV2 =(的TextView)findViewById(R.id.basetext);;

I have tried: TextView tv1 = new TextView(this); TextView tv2 = (TextView) findViewById(R.id.basetext);;

    // its this line below which doesn't work
    tv1.setLayoutParams(tv2.getLayoutParams());

但它不会复制任何布局参数...

But it doesn't copy any of the layout parameters...

任何想法?

推荐答案

您可以做的一件事。

如果你想每次都设置相同TextValue刚值,如果是的TextView的布局属性是在所有的时间相同,然后按照下列步骤进行:

If you are trying to set just the Value of the Same TextValue every time and if the Layout properties of that TextView is same at all the time then follow below steps:


  1. 首先创建一个布局仅包含他的TextView布局只与您相应的属性。 (我们将其命名为layout_textView.xml)

  1. First Create the One Layout that only contain he TextView layout only with your appropriate properties. (Let name it as layout_textView.xml)

现在,不要添加la​​yout_textView.xml动态到主视图按照您的要求。

Now, do add that layout_textView.xml dynamically to your main view as per your requirement.

它将如何解决问题。

如果任何查询,然后让我知道。

If any query then let me know.

享受编码。 。 。

:)

这篇关于Dynamiclly使用现有的TextView布局参数添加一个TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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