2012-12-11 46 views
0

enter image description here的Android tableLayout與圖像的高度和寬度

欲膨脹的ImageView,tablelayout,tablerow的,然後添加到imageviews tablerows然後添加tablerows到tablelayout。

問題是我無法管理圖像的寬度和高度。

enter image description here

,當我在XML創建表靜態我曾與圖像沒有問題。但是現在你可以看到它甚至沒有顯示該表所有的三行。我究竟做錯了什麼?

而我想要的是具有動態數量的列和行的表。我希望這張桌子適合屏幕。

 for (int i = 0; i < im1.length; i++) { 
     im1[i] = (ImageView) getLayoutInflater().inflate(R.layout.image0, null); 
     im2[i] = (ImageView) getLayoutInflater().inflate(R.layout.image1, null); 
    } 


    table = (TableLayout) getLayoutInflater().inflate(R.layout.table, null); 
    TableRow row1 = (TableRow) getLayoutInflater().inflate(R.layout.row, null); 
    row1.addView(im1[0]); 
    row1.addView(im2[0]); 
    TableRow row2 = (TableRow) getLayoutInflater().inflate(R.layout.row, null); 
    row2.addView(im1[1]); 
    row2.addView(im2[1]); 
    TableRow row3 = (TableRow) getLayoutInflater().inflate(R.layout.row, null); 
    row3.addView(im1[2]); 
    row3.addView(im2[2]); 

    table.addView(row1); 
    table.addView(row2); 
    table.addView(row3); 
    tableFlipper.addView(table); 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/llayout" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
tools:context=".MainActivity" > 


<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:text="@string/hello_world" 
    android:layout_marginTop="10dp" /> 

<ViewFlipper 
    android:id="@+id/tableFlipper" 
    android:layout_width="wrap_content" 
    android:layout_height="400dp" 
    android:layout_gravity="center" 
    android:layout_marginTop="10dp" >  

</ViewFlipper> 

<Button 
    android:id="@+id/button1" 
    style="?android:attr/buttonStyleSmall" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" 
    android:layout_gravity="center" 
    android:layout_marginTop="10dp" 
    android:onClick="onButtonClick" /> 

    </LinearLayout> 

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:shrinkColumns="*" > 


</TableLayout> 

<?xml version="1.0" encoding="utf-8"?> 
<TableRow xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
> 


</TableRow> 

<?xml version="1.0" encoding="utf-8"?> 
<ImageView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:src="@drawable/square" 
android:scaleType="fitCenter" 
android:maxHeight="30dp" 
android:maxWidth="30dp" >  

回答

0

所以你無法控制TableRow佈局的高度。它總是wrap_content。