【发布时间】:2012-02-17 01:22:33
【问题描述】:
我找不到任何教程或示例如何做到这一点。这应该很容易,但我想不通。
所以我有很多按钮的RelativeLayout,那么我如何让按钮在每次活动开始时出现在该布局的随机位置?
例如。第一次活动开始一个出现在右下角和一个屏幕中间和一个右上角。下次我打开相同的活动时,这些按钮在布局的中间下方和左上角等等?
【问题讨论】:
标签: android android-layout android-button
我找不到任何教程或示例如何做到这一点。这应该很容易,但我想不通。
所以我有很多按钮的RelativeLayout,那么我如何让按钮在每次活动开始时出现在该布局的随机位置?
例如。第一次活动开始一个出现在右下角和一个屏幕中间和一个右上角。下次我打开相同的活动时,这些按钮在布局的中间下方和左上角等等?
【问题讨论】:
标签: android android-layout android-button
Button mButton = new Button(context);
params = new RelativeLayout.LayoutParams(pxVal*2, pxVal);//size of ur button
params.addRule(ALIGN_PARENT_RIGHT);
params.addRule(ALIGN_PARENT_TOP);
params.rightMargin = pxMarginH;//u can set ur margin u want,
params.topMargin = pxMarginH; //then u can set the button place u want
this.addView(mSearchButton, params);
我认为这可以解决你的问题
【讨论】: