套装属性(保证金,重力等)到Android编程视图(无XML) [英] Set attributes (margin, gravity, etc...) to an Android view programmatically (without XML)
本文介绍了套装属性(保证金,重力等)到Android编程视图(无XML)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在我的.java活动类来创建一个GUI(布局+视图)(我知道这是更加灵活和更容易使用的.xml布局文件,但我不希望使用它)。
I need to create a GUI (layout+views) in my .java activity class (I know it's far more flexible and easier to use .xml layout file, but I don't want to use it for now).
我找不到(我想不出如何使用,但一个万有引力对象)视图对象中的任何setGravity()或任何一套setMargin()方法。
I can't find any setGravity() (but a "Gravity" object I can't figure how to use) or any set setMargin() method for the "View" object.
什么是做的最简单的方法?
What is the easiest way to do it ?
感谢名单。
推荐答案
有关上设置组件的保证金。下面会保持现有的利润率为previously设置,并设置左边距为零。
For setting the margin on component. The following leaves the existing margins as previously set and sets the left margin as zero.
TextView title = ((TextView)findViewById(R.id.default_panel_title))
final ViewGroup.MarginLayoutParams lpt =(MarginLayoutParams)title.getLayoutParams();
lpt.setMargins(0,lpt.topMargin,lpt.rightMargin,lpt.bottomMargin);
title.setLayoutParams(lpt);
这篇关于套装属性(保证金,重力等)到Android编程视图(无XML)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文