在调整大小和分配位图后调整ImageView的大小
问题描述:
我有一个ImageView
,调整后的位图大小适合。下面是截图在调整大小和分配位图后调整ImageView的大小
我已经设置白颜色ImageView
背景。因此在所有屏幕中都可以看到ImageView
。
我想要的是,当我设置图像,使其填满它最大我如何可以调整ImageView
以适应图像绘制它显示,这是调整ImageView
,这样它不显示任何白色。
答
尝试使用wrap_content
作为其宽度和高度
+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"
/>
希望这将帮助你..
答
它不会填满您的所有屏幕(或将被屏蔽) 只需设置wrap_content
至height
并将match_parent
保留为width
答
这个固定我的问题
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);
}
}
你没事吧与图像被拉伸成为一个更大的高度? – cjnash