2017-08-04 127 views
0

我有一个ImageView,调整后的位图大小适合。下面是截图在调整大小和分配位图后调整ImageView的大小

enter image description here

我已经设置白颜色ImageView背景。因此在所有屏幕中都可以看到ImageView

我想要的是,当我设置图像,使其填满它最大我如何可以调整ImageView以适应图像绘制它显示,这是调整ImageView,这样它不显示任何白色。

+0

你没事吧与图像被拉伸成为一个更大的高度? – cjnash

回答

0

尝试使用wrap_content作为其宽度和高度

+0

我尝试过,但它使图像减少其宽度,并尽量让它适合全屏 –

0

设置规模类型fitXY在ImageView的像这样的xml文件:

<ImageView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/imageView" 
android:layout_height="match_parent" 
android:layout_width="match_parent" 
android:background="@drawable/locked_image" 
android:scaleType="fitXY" 
/> 

希望这将帮助你..

0

它不会填满您的所有屏幕(或将被屏蔽) 只需设置wrap_contentheight 并将match_parent保留为width

0

这个固定我的问题

public class MyImageView extends CropImageView 
{ 
    public int mVideoWidth = 0; 
    public int mVideoHeight = 0; 

    private boolean isFixed = false; 

    public MyImageView(Context context, AttributeSet attrs) 
    { 
     super(context, attrs); 
    } 

    public MyImageView(Context context, AttributeSet attrs, int defStyle) 
    { 
     super(context, attrs, defStyle); 
    } 

    public MyImageView(Context context) 
    { 
     super(context); 
    } 

    public void setImageSize(int width, int height) 
    { 
     mVideoWidth = width; 
     mVideoHeight = height; 
     invalidate(); 
    } 

    @Override 
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 
    { 
     // Log.i("@@@", "onMeasure"); 
     int width = getDefaultSize(mVideoWidth, widthMeasureSpec); 
     int height = getDefaultSize(mVideoHeight, heightMeasureSpec); 
     if (mVideoWidth > 0 && mVideoHeight > 0) 
     { 
      if (mVideoWidth * height > width * mVideoHeight) 
      { 
       height = width * mVideoHeight/mVideoWidth; 
      } else if (mVideoWidth * height < width * mVideoHeight) 
      { 
       width = height * mVideoWidth/mVideoHeight; 
      } else 
      { 
       // Log.i("@@@", "aspect ratio is correct: " + 
       // width+"/"+height+"="+ 
       // mVideoWidth+"/"+mVideoHeight); 
      } 
     } 
     setMeasuredDimension(width, height); 
    } 
}