1
private void addSnapPictureRow(TableLayout table, Bitmap bitmap) {
/*
* 1st row = TextView (Check In)
*/
TableRow row = new TableRow(this);
row.setGravity(Gravity.CENTER_HORIZONTAL);
// add text
TextView text = new TextView(this);
text.setText("Snap Picture");
TableRow.LayoutParams textLayoutParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
textLayoutParams.setMargins(100, 0, 0, 0);
row.addView(text, textLayoutParams);
// add picture
ImageView picture = new ImageView(this);
picture.setImageResource(R.drawable.adium);
row.addView(picture);
/*
* 2nd row = View (separator)
*/
TableRow separator = new TableRow(this);
View line = new View(this);
TableRow.LayoutParams separatorLayoutParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, 1);
separatorLayoutParams.setMargins(100, 0, 0, 0);
line.setBackgroundColor(Color.BLUE);
separator.addView(line, separatorLayoutParams);
// add row to table
table.addView(row);
// add a separator
table.addView(separator);
}
但是畫面一直沒有露面。如果我將重力改變爲CENTER_HORIZONTAL
,那麼它只顯示圖片的一小部分。
當創建XML表,我想它會自動水平對齊。我無法理解TableRow佈局是如何工作的。任何人都可以向我提供一些啓示嗎?