简体   繁体   English

如何在屏幕上以编程方式移动项目?

[英]How can i move items programmatically on the screen?

I have an image with an item in the lower left. 我的图像左下方有一个项目。 I would like at the bottom center, and not attached at the lower end but slightly raised. 我想在底部中心,而不是在下端附着,而是略微抬起。 How can I do? 我能怎么做? Working with some of the calculations on the size of the screen? 使用一些关于屏幕大小的计算? Obviously I mean in code, not xml. 显然我的意思是代码,而不是xml。 thanks 谢谢

have a look at LayoutParams . 看看LayoutParams

for exmaple 例如

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
Button button1;
button1.setLayoutParams(params);

you can do all differnt alignments, params, margins and padding as in xml 您可以像在xml中那样执行所有不同的对齐,参数,边距和填充

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM