【发布时间】:2012-08-23 16:04:19
【问题描述】:
我在图像视图中有一个矩形图像。我想在保持纵横比的同时,使图像适合不同的屏幕尺寸。
在较小的屏幕上它可以正常工作,但在较大的屏幕上它不会被拉伸。图片底部仍有一些空隙。
这是我的代码:
LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
LayoutParams params1 = new LayoutParam(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
mMainLayout = new LinearLayout(context);
mMainLayout.setLayoutParams(params);
backgroundImage = new ImageView(context);
backgroundImage.setId(0);
backgroundImage.setAdjustViewBounds(true);
backgroundImage.setScaleType(ScaleType.FIT_CENTER);
backgroundImage.setLayoutParams(params1);
backgroundImage.setImageResource(R.drawable.background_circles_en);
mMainLayout.addView(backgroundImage);
我使用了fill_parent、wrap_content 与多个 scaleTypes 的许多组合:fitCenter、centerInside,它们都以正确的纵横比绘制图像,但它们都没有真正放大图像并且ImageView 本身,导致 TextView 一直被推离屏幕、ImageView 内有空白区域或图像未缩放。
请给出正确的组合,使其适用于不同的屏幕尺寸。
【问题讨论】:
标签: android android-layout fullscreen