我正在尝试在TableRow中显示一个简单的ImageView,但由于某种原因它无法显示。如果我将另一个控件添加到另一行,则ImageView会显示出来,因此似乎它只是没有正确强制大小。我的xml如下:
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="#4B088A"
android:id="@+id/ImageTable">
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:id="@+id/ImageTableRow"/>
</TableLayout>
我正在使用的代码来添加ImageView如下:
TableLayout tableLayout = (TableLayout) findViewById(R.id.ImageTable);
TableRow tr = new TableRow(this);
TableRow.LayoutParams lp = new
TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT ,TableRow.LayoutParams.WRAP_CONTENT);
tr.setLayoutParams(lp);
m_imageView = new MyImageView(getApplicationContext());
m_imageView.setBackgroundColor(Color.GRAY);
m_imageView.setImageBitmap(charty);
tr.addView(m_imageView);
tableLayout.addView(tr);