2011-09-30 22 views
1

TableLayout沒有縮水我試圖創建8X5圖像作爲一個表中的所有圖片

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    TableLayout table = new TableLayout(this); 

    table.setStretchAllColumns(true); 
    table.setShrinkAllColumns(true); 

    for(int i = 0; i < 6; i++){  
     TableRow card = new TableRow(this); 
     card.setGravity(Gravity.CENTER); 

     for(int j = 0; j < 5; j++){ 
      TableRow.LayoutParams paramsCard = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
      paramsCard.setMargins(CARDS_MARGIN,CARDS_MARGIN,CARDS_MARGIN,CARDS_MARGIN); 
      ImageView imgCard = new ImageView(this); 
      imgCard.setImageResource(R.drawable.dos); 
      imgCard.setLayoutParams(paramsCard); 
      card.addView(imgCard); 
     } 
     table.addView(card); 
    } 
    setContentView(table); 
    table.setBackgroundDrawable(getResources().getDrawable(R.drawable.background)); 
} 

但在最後一排,我得到的圖像更小,爲什麼呢?我明顯地設置了

table.setStretchAllColumns(true); 
    table.setShrinkAllColumns(true); 

enter image description here

http://dl.dropbox.com/u/3340490/device-2011-10-01-002223.png

+0

如果從xml文件加載該佈局,會發生同樣的事情嗎? –

+0

我需要以編程方式進行。你的意思是如果我膨脹TableLayout? – Dayerman

+0

是的,因爲通過代碼完全創建佈局有時會產生奇怪的結果 –

回答

0

最後我用一個LinearLayout,將重量設置爲1來自動調整爲屏幕大小。 TableLayout在調整圖像方面效果不佳。

0

我敢打賭,你,你的TableView中處於​​的LinearLayout或一些東西,不會可用屏幕的溢出 - 所以最後意見縮水到有一切都適合那裏 - 也許......你能確保你的TableView在ScrollView中,看看是否會發生?

-serkan

+0

正如你可以看到代碼TableLayout table = new TableLayout(this);我的主要佈局是一個TableLayout,而不是一個LinearLayout。 – Dayerman

+0

是的,你可以把它放在ScrollView中,然後嘗試嗎? – serkanozel

+0

可能會工作,但我不想使用ScrollView。 – Dayerman

0

如果u有給出的保證金或填充到外佈局這是TableLayout的父,然後將其設置。 它會發生有時只是因爲你給了一些邊緣和一些填充到TableLayout的父佈局。 希望它能幫助你。 謝謝。

相關問題