如何设置RelativeLayout的固定大小和位置?
Android实现了默认的布局规则,比如measure、layout等,我没有发现有方法可以设置这样的固定大小。如何摆脱默认布局行为?
实际上,就我而言,每个视图都应该相对于其父视图,并且具有指定的大小。我该怎么办?
谢谢
Android implemented a default layout rule, like measure, layout, etc, I didn't find out there is a method to set such a fixed size. How to get rid of that default layout behavior?
Actually, in my case, every view is supposed to be relative to its parent, and will have a specified size., how could I do?
Thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定我是否正确理解你的问题,但你可以指定某些视图的大小(例如RelativeLayout、LinearLayout 或某些控件)。在布局视图的属性(
Layout width
、Layout height
)中,您不需要仅使用wrap_content
或fill_parent
>。您还可以输入尺寸,例如40dip
。如果您以动态方式创建视图,那么您应该设置 LayoutParams。例如,要定义relativelayout的元素大小和边距(与其他布局类似),您应该使用类似以下内容的内容:
Not sure if I correctly understood your issue, but you can specify size of certain View (e.g. RelativeLayout, LinearLayout or certain control). In Properties of your layout view (
Layout width
,Layout height
) you do not need to use onlywrap_content
orfill_parent
. You are also allowed to type size like40dip
.If you created your View dinamically, then you should set LayoutParams. For example, to define your element size and margins for RelativeLayout (similar for others) you should use something like: