2017-08-04 121 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); 
    } 
}