繁体   English   中英

位图图像未填充宽度

[英]Bitmap image not filling width

我的位图图像拒绝填充父宽度。

ImageView imgView = (ImageView) getLayoutInflater().inflate(R.layout.image_layout, null);
imgView.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT));
imgView.setScaleType(ImageView.ScaleType.FIT_XY);
imgView.setAdjustViewBounds(true);
imgView.setImageBitmap(fileBitmap);

但是当我设置imgView.setImageResource(R.drawable.img); imgView.setImageBitmap(fileBitmap);使用相同的图像imgView.setImageBitmap(fileBitmap); 我得到了所需的结果。 下面是我的image_layout

<?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="wrap_content"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"
    android:clickable="true"/>

我不知道还能做什么

好的,我明白了……我必须调整图像大小以适应屏幕宽度

//after declaring my variables
displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
width = displayMetrics.widthPixels;

if(width > fileBitmap.getWidth()) {
    int newWidth = width;
    int newHeight = width * fileBitmap.getHeight() / fileBitmap.getWidth();
    fileBitmap = Bitmap.createScaledBitmap(fileBitmap, newWidth, newHeight, false);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM