用java代码在android中设置Button的宽度和高度的问题 [英] Problem in setting width and height of a Button in android by java code

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

问题描述

在Android应用中,我在MainActivity类上有这个代码来设置按钮的宽度和高度 -



In an Android app, I have this code on my MainActivity class to set width and height of a Button -

Button butn = (Button)findViewById(R.id.butn);
butn.setHeight(30);
butn.setWidth(70);





但是这个按钮大小对于所有大小的模拟器都是相同的。



有没有什么方法可以让我将高度和宽度设置为屏幕高度和宽度的百分比?



But this Button size is same for all sizes of emulator.

Is there any way that lets me set the height and width as some percentage of screen height and width ?

推荐答案

请参阅 http://stackoverflow.com/questions/15897553/change -height-of-android-button-through-code [ ^ ]。


这篇关于用java代码在android中设置Button的宽度和高度的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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