Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有图像高度和宽度的Android桌面布局_Android_Tablelayout - Fatal编程技术网

具有图像高度和宽度的Android桌面布局

具有图像高度和宽度的Android桌面布局,android,tablelayout,Android,Tablelayout,我想膨胀imageview、tablelayout、tablerow,然后将imageview添加到tablerows,然后将tablerows添加到tablelayout 问题是我无法管理图像的宽度和高度 当我用xml静态创建表时,我对图像没有任何问题。但现在您可以看到,它甚至没有显示表中的所有三行。我做错了什么 我想要的是具有动态列数和行数的表。我希望这张桌子适合屏幕 for (int i = 0; i < im1.length; i++) { im1

我想膨胀imageview、tablelayout、tablerow,然后将imageview添加到tablerows,然后将tablerows添加到tablelayout

问题是我无法管理图像的宽度和高度

当我用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);
for(int i=0;i









所以您无法控制TableRow布局的高度。它总是包装内容

<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" >