我試圖在圖像中放置圖像和一些文本,圖像的高度是文本高度的兩倍,以便兩行文本可以放在圖像的旁邊,就像所以:在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