如何在 android 中动态的添加 checkboxs

如何在 android 中动态的添加 checkboxs,第1张

先用一个TextView获得你的基准控件的id,这样这个TextView就是那个基准控件了,然后新建一个TextView在后面找库函数,设置在基准控件的右边就行了,最后别忘了加上contentView函数

private LinearLayout.LayoutParams LP_FF = new LinearLayout.LayoutParams (LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)ScrollView sv = new ScrollView(this)sv.setLayoutParams( LP_FF )LinearLayout layout = new LinearLayout(this)//线性布局方式 layout.setOrientation( LinearLayout.VERTICAL )//控件对其方式为垂直排列 sv.addView( layout )//把线性布局加入到ScrollView中 setContentView(sv)//设置当前的页面为ScrollView CheckBox tv = new CheckBox(this)tv.setId(10)tv.setText( "fsdfsdfsdfsd" )layout.addView( tv )


欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/bake/7973677.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-12
下一篇2023-04-12

发表评论

登录后才能评论

评论列表(0条)

    保存