如何设置一个按钮相同的宽度和高度 [英] How to set same width and height of a button

查看:650
本文介绍了如何设置一个按钮相同的宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XML布局文件中,我有一个按钮。在按钮的高度设置为 match_parent 。现在我想的宽度是一样的按钮的高度,使一个方形按钮,无论改变父布局的高度和宽度。

I have a xml layout file in which I have a Button. The Height of the Button is set as match_parent. Now I want the Width to be the same as the Height of the Button to make a square button regardless of changing Height and Width of parent layout..

推荐答案

这个怎么样:

Button yourBtn = (Button) findViewById.(R.id.yourBtn);

int btnSize=yourBtn.getLayoutParams().width;
yourBtn.setLayoutParams(new LayoutParams(btnSize, btnSize));

这篇关于如何设置一个按钮相同的宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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