如何在Android中动态添加一个按钮? [英] How to add a button dynamically in Android?
本文介绍了如何在Android中动态添加一个按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何添加动态地在Android的一个按钮?
解决方案
按钮myButton的=新的按钮(这一点);
myButton.setText(推我);
的LinearLayout LL =(的LinearLayout)findViewById(R.id.buttonlayout);
的LayoutParams LP =新的LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
ll.addView(myButton的,LP);
看一看到<一个href="http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ScrollView2.html">this例如
How to add a button dynamically in Android?
解决方案
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);
Have a look to this example
这篇关于如何在Android中动态添加一个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文