随机按钮出现的位置?

时间:2012-02-17 01:22:34

标签: android android-layout android-button

我找不到任何教程或示例如何执行此操作。它应该很容易,但我无法弄明白。

所以我有RelativeLayout,其中有很多按钮,所以每次活动开始时如何让按钮出现在该布局的随机位置?

例如。第一次活动开始时出现一个右下角和一个屏幕中间和一个右上角的位置。下次我打开相同的活动时,这些按钮位于布局的中间位置和左上角,依此类推?

1 个答案:

答案 0 :(得分:0)

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);

我认为这可以解决您的问题

相关问题