gpt4 book ai didi

java - 创建一个给定宽度的按钮

转载 作者:行者123 更新时间:2023-12-01 14:59:03 24 4
gpt4 key购买 nike

Possible Duplicate:
how to add button dynamically in android?

我需要在android中创建一个按钮而不使用xml。我尝试了以下代码:

Button b=new Button(this);
b.setWidth(50);

但是,它不会在运行时显示。

最佳答案

 Button myButton = new Button(this);
myButton.setText("Push Me");
myButton.height = 60;
myButton.width = 60;
LinearLayout ll = (LinearLayout)findViewById(R.id.buttonlayout);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
ll.addView(myButton, lp);

关于java - 创建一个给定宽度的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13950121/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com