在Android中动态设置TextView的宽度和高度 [英] Dynamically set width and height of TextView in Android

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

问题描述

我正在尝试使用setWidth(width)方法动态设置TextView宽度.

I am trying to set TextView width dynamically, Using setWidth(width) method.

txtviewOne.setWidth(10);
txtviewTwo.setWidth(10);

但没有成功.

请帮助我如何动态设置textview的宽度.

Please help me How can I set width of textview dynamically.

推荐答案

TextView tv;
----------------------
tv=new TextView(this);   // or  tv=new TextView(R.id.textview1);

LinearLayout.LayoutParams Params1 = new LinearLayout.LayoutParams(15,50);
tv.setLayoutParams(Params1);  

这篇关于在Android中动态设置TextView的宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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