【发布时间】:2013-06-08 22:23:46
【问题描述】:
在我的一项活动中,我有一个表格布局,其中包含在运行时通过自定义类添加的单元格。我的单元格的布局如下:
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+cell/style_2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp" >
<View
android:id="@+cell/divider"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#FF000000" />
<ImageView
android:id="@+cell/image"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@cell/divider"
android:layout_margin="5dp"
android:contentDescription="@string/row_thumbnail"
android:scaleType="fitCenter"/>
</RelativeLayout>
</TableRow>
这会被以下类夸大:
public Cell(Context context) {
super(context);
addView(((LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.gallery_row_1, null));
}
当我给单元格充气时,我还设置了一个图像用作显示,问题是图像视图的大小没有保持应有的大小,找不到右边缘,并且图像永远不会显示(可能在某个地方偏右?),我不确定我的问题出在哪里。
c = new Cell(this);
c.getImageView().setImageBitmap(BitmapFactory.decodeStream(assetManager.open("categories" + File.separator + sec + File.separator + filename)));
page.addView(c);
getImageView 是我的 Cell 中的一个函数,它返回实际的 ImageView 元素。
我知道图像被放置在 ImageView 中,因为当布局参数更改时,我可以看到图像,只是大小不合适。
所需的输出应该是一个视图,顶部是一个分割视图,下面是一个 ImageView,填充父级并且高 100dp。图像,无论原始尺寸如何,都应缩放并显示在里面。
另外,如果我注释掉我将图像设置为 ImageView 的行,则布局边界是正确的,在启用 Show Layout Bounds 的情况下查看。
我的总体问题是,为什么我的 ImageView 在应用图像时会重新调整大小。
非常感谢任何和所有帮助。
【问题讨论】:
标签: android image view imageview scale