【发布时间】:2019-06-08 05:15:33
【问题描述】:
我制作了一些按钮并将它们存储到一个 ArrayList 中。我需要将这些按钮添加到我的主要活动布局中。
我尝试创建一个线性布局并将其作为我的主要布局,但是按钮不显示。
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// createButtons();setContentView(new CircleView(this));
}
public void createButtons() {
ArrayList<Button> buttons = new ArrayList<>();
int n = 0; // the number of buttons circumferencing the semicircle
for(int i = 0; i < 6; i ++) {
n = 7;
Button button = new Button(this);
double Xval = 500* Math.cos(i * Math.PI / n);
double Yval = 500* Math.sin(i * Math.PI / n);
button.setX((float)(Xval));
button.setY((float)(Yval));
buttons.add(button);
}
}
}
我希望我的按钮出现在我的主要活动布局中。
【问题讨论】:
-
你没有在布局中添加按钮
-
如何将按钮添加到布局中?
-
在你问这个问题之前我已经链接了这个问题