如何在Android属性layout_alignParentBottom动态设置到一个按钮 [英] How to set the android property layout_alignParentBottom to a button dynamically

查看:5622
本文介绍了如何在Android属性layout_alignParentBottom动态设置到一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动态的布局,我有一个按钮。我怎么可以在酒店 layout_alignParentBottom 设置为按钮,它会出现在我的相对布局的底部?

I have a dynamic layout and I have a button. How can I set the property layout_alignParentBottom to that button so that it would appear in the bottom of my relative layout?

或者你知道另一种方式?

Or do you know another way?

推荐答案

这只会工作,如果你的布局是一个RelativeLayout的,因为其他ViewGroups不明白alignParentBottom。

This will only work if your layout is a RelativeLayout, as other ViewGroups don't understand alignParentBottom.

RelativeLayout layout = findViewById(R.id.my_relative_layout);
Button button = new Button(this); // your button
lp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); // You might want to tweak these to WRAP_CONTENT
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layout.addView(button, lp);

这篇关于如何在Android属性layout_alignParentBottom动态设置到一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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