3 回答
TA贡献1848条经验 获得超2个赞
addView
Button myButton = new Button();
setLayoutParams
onCreate()
R.id.main
:
LinearLayout myLayout = findViewById(R.id.main);Button myButton = new Button(this);myButton.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));myLayout.addView(myButton);
TA贡献1827条经验 获得超7个赞
虽然为时已晚,但这可能会帮助某人:)以编程方式添加视图,请尝试如下
LinearLayout rlmain = new LinearLayout(this);
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT);
LinearLayout ll1 = new LinearLayout (this);
ImageView iv = new ImageView(this);
iv.setImageResource(R.drawable.logo);
LinearLayout .LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
iv.setLayoutParams(lp);
ll1.addView(iv);
rlmain.addView(ll1);
setContentView(rlmain, llp);
这将以编程方式创建整个视图。您可以添加相同数量的视图。希望这能帮上忙。*)
- 3 回答
- 0 关注
- 279 浏览
添加回答
举报