设置图像高度和宽度android ..!

时间:2016-01-27 23:12:10

标签: android

在我的应用程序中,我将图像从SD卡插入到imageview。 如何设置图像宽度=窗口宽度,图像高度将按宽高比自动设置。

在此之后,我将按矩阵转换图像。

我正在使用此代码

int height;
int width;

String[] template_array;
ImageView imgTemplate;
int position = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gallery_image);


    height = getWindowManager().getDefaultDisplay().getHeight();
    width = getWindowManager().getDefaultDisplay().getWidth();
    InitUI();
    // InitPager();
    DisplayImage();
    SetonClickListners();
}

1 个答案:

答案 0 :(得分:0)

将图像视图的宽度设置为MATCH_PARENT,将高度设置为WRAP_CONTENT,将scaleType设置为centerInside。这将使其保持纵横比,具有全屏宽度,并停止缩放图像,使其适合屏幕。

相关问题