Android的设置布局的参数编程 [英] Setting parameter of layout of android programmatically

查看:101
本文介绍了Android的设置布局的参数编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的机器人。我想知道如何设置参数或属性从程序像任何绝对布局布局x和布局ÿ宽度和高度。

I am new to android. I want to know how to set the parameters or attributes to layout x and layout y width and height from the program for any layouts like absolute.

推荐答案

有关按钮,你可以尝试这样的:

For button you can try like this:

RelativeLayout.Layoutparams params = (RelativeLayout.LayoutParams)button.getLayoutParams();
params.setMargins(5, 5, 5, 5);
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
button.setLayoutParams(params);

您setMargins()到您分别通过左,上,右,下值。

you have setMargins() to which you pass the left, top, right and bottom values respectively.

这篇关于Android的设置布局的参数编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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