【问题标题】:Android tableLayout with images height and width具有图像高度和宽度的Android tableLayout
【发布时间】:2012-12-11 10:01:08
【问题描述】:

我想膨胀 imageview、tablelayout、tablerow,然后将 imageviews 添加到 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);

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

【问题讨论】:

    标签: android tablelayout


    【解决方案1】:

    因此您无法控制 TableRow 布局的高度。它始终是 wrap_content。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多