我试图在图像中放置图像和一些文本,图像的高度是文本高度的两倍,以便两行文本可以放在图像的旁边,就像所以:在TableLayout中放置LinearLayout的问题
_____
| |text here
|_____|text here
我试图做到这一点的方法是将两个TextViews在LinearLayout中,然后将ImageView的和的LinearLayout,包含文本,在TableLayout一个行和两列。
当我这样做,我只有在ImageView。实际上,即使我将ImageView添加到表中,LinearLayout中的文本也不会显示出来。
任何帮助代码或不同的布局方法是非常感谢。
LinearLayout tempVindLayout = new LinearLayout(this);
tempVindLayout.setOrientation(LinearLayout.VERTICAL);
tempVindLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
TableLayout tabellLayout = new TableLayout(this);
tabellLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
tabellLayout.setPadding(0, 60, 0, 0);
TableRow row1 = new TableRow(this);
row1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
// Textview saturday
TextView tempSat = new TextView(this);
tempSat.setText("+13");
tempSat.setTextAppearance(this, R.style.RegularSmall);
tempSat.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
// Wind saturday
TextView vindSat = new TextView(this);
vindSat.setText("5 m/s");
vindSat.setTextAppearance(this, R.style.RegularSmall);
vindSat.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
//Image for weather icons
ImageView imgSat = new ImageView(this);
imgSat.setImageResource(R.drawable.solmoln);
imgSat.setAdjustViewBounds(true);
// Add to table
tempVindLayout.addView(tempSat);
tempVindLayout.addView(vindSat);
row1.addView(tempVindLayout);
row1.addView(imgSat);
tabellLayout.addView(row1);
setContentView(tabellLayout);
这是很容易看到如果您使用xml文件创建布局,而不是在代码中执行,会发生什么情况。 – 2010-11-08 22:56:06