为了账号安全,请及时绑定邮箱和手机立即绑定

如何在Android中动态添加按钮?

如何在Android中动态添加按钮?

开满天机 2019-07-12 09:32:14
如何在Android中动态添加按钮?如何在Android中动态添加按钮?
查看完整描述

3 回答

?
倚天杖

TA贡献1828条经验 获得超3个赞

Button myButton = new Button(this);
myButton.setText("Push Me");

LinearLayout ll = (LinearLayout)findViewById(R.id.buttonlayout);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
ll.addView(myButton, lp);

看一看这,这个


查看完整回答
反对 回复 2019-07-12
?
湖上湖

TA贡献2003条经验 获得超2个赞

试试这个:

LinearLayout ll = (LinearLayout)findViewById(R.id.layout);Button btn = new Button(this);btn.setText("Manual Add");
btn.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));ll.addView(btn);


查看完整回答
反对 回复 2019-07-12
  • 3 回答
  • 0 关注
  • 1888 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号