java 在java中设置TextView宽度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4004397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting a TextView width in java
提问by Annjo
How can I set the TextView properties like width, height using Java Code?
如何使用 Java 代码设置 TextView 的宽度、高度等属性?
回答by espinchi
In the activity where you inflate the view, you can grab the TextViewwith
在您膨胀鉴于活动,你可以抓住的TextView用
TextView t = (TextView)findViewById(R.id.myTextView);
where myTextViewis the idthat you declared in your XML.
这里myTextView是id您在XML声明。
Now go ahead and t.setText("Something");, t.setWidth(200), ...
现在继续t.setText("Something");,t.setWidth(200)...
回答by Cristian
Here you have all TextViewmethods:
在这里你有所有的TextView方法:
http://developer.android.com/reference/android/widget/TextView.html
http://developer.android.com/reference/android/widget/TextView.html
If you read the complete page, then you will become a TextViewguru.
如果您阅读完整的页面,那么您将成为一名TextView大师。

