我在TextView和TableLayout下使用了LinearLayout。
输出:
我可以在模型中看到TextView内容,但不能看到TableLayout。
请告诉我我犯的错误是什么?
LinearLayout quizlinear = new LinearLayout(this);
quizlinear.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.FILL_PARENT));
quizlinear.setOrientation(LinearLayout.VERTICAL);
quizlinear.setBackgroundColor(Color.BLACK);
quiztextview = new TextView(this);
quiztextview.setText("BEER THERE");
quiztextview.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
quiztextview.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);
quiztextview.setTextColor(Utils.getColor("#FFFFFF"));
quiztextview.setTextSize(30);
quizlinear.addView(quiztextview);
quiztablelayout = new TableLayout(this);
TableRow quiztablerow = new TableRow(this);
quiztablerow.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
TableRow quiztablerow1 = new TableRow(this);
quiztablerow1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
ImageView arrowImg1 = new ImageView(this);
arrowImg1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));
arrowImg1.setImageResource(R.drawable.icon);
quiztablerow.addView(arrowImg1);
ImageView arrowImg2 = new ImageView(this);
arrowImg2.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));
arrowImg2.setImageResource(R.drawable.icon);
quiztablerow.addView(arrowImg2);
ImageView arrowImg3 = new ImageView(this);
arrowImg3.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));
arrowImg3.setImageResource(R.drawable.icon);
quiztablerow1.addView(arrowImg3);
ImageView arrowImg4 = new ImageView(this);
arrowImg4.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));
arrowImg4.setImageResource(R.drawable.icon);
quiztablerow1.addView(arrowImg4);
quiztablelayout.addView(quiztablerow,new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
quiztablelayout.addView(quiztablerow1,new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
quizlinear.addView(quiztablelayout);
TextView quiztextview1 = new TextView(this);
quiztextview1.setText("DONE THAT!");
quiztextview1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
quiztextview1.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);
quiztextview1.setTextColor(Utils.getColor("#FFFFFF"));
quiztextview1.setTextSize(30);
quizlinear.addView(quiztextview1);
TextView quiztextview2 = new TextView(this);
quiztextview2.setText("Version1.0 copyrights @2011 janardhan solutions pvt ltd");
quiztextview2.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
quiztextview2.setTypeface(Typeface.SANS_SERIF);
quiztextview2.setGravity(Gravity.CENTER);
quiztextview2.setTextColor(Utils.getColor("#FFFFFF"));
quiztextview2.setBackgroundColor(Color.BLUE);
quiztextview2.setTextSize(10);
quizlinear.addView(quiztextview2);
setContentView(quizlinear);
答案 0 :(得分:0)
更改你的LayoutParams应该是android.widget.TableRow.LayoutParams,除了提供给 quiztablelayout .addView(...)
的那个quiztablelayout.addView(quiztablerow,new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
quiztablelayout.addView(quiztablerow1,new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
quizlinear.addView(quiztablelayout);