
期望的效果是,image的高度height是自动的。
网上好多说把image的mode设置为widthFit。这种方法还是需要给image设置宽度高度。并不是height自动,而是height固定,在显示的时候,显示的区域在高度上是自适应的
所以还是需要用js计算
imageLoad: function(e) {
var $width=edetailwidth,//获取真实宽度
$height=edetailheight,
ratio=$width/$height; //的真实宽高比例varviewWidth=718,//设置显示宽度,左右留有16rpx边距viewHeight=718/ratio; //计算的高度值varimage=thisdataimages;
//将的datadata-index作为image对象的key,然后存储的宽高值
image[etargetdatasetindex]={
width:viewWidth,
height:viewHeight
}
thissetData({
images:image
})
}
>
BITMAP bmp;
int bmp_width;
int bmp_height;
if(GetObject(hBmp,sizeof(BITMAP),(LPSTR)&bmp))
{
bmp_width=bmpbmWidth;
bmp_height=bmpbmHeight;
}
在ImageView中的image,可以使用getWidth()和getHeight()来获取宽度和高度,但是获得的image宽度和高度不是很精确的;对于背景,你首先要获取背景的Drawable对象,然后将Drawable对象转换为BitmapDrawable,这样你就可以将背景作为Bitmap对象并获取其宽度和高度了。代码如下:Bitmap b = ((BitmapDrawble)imageViewgetBackground())getBitmap(); int w = bgetWidth(); int h = bgetHeight(); or do like this wayimageViewsetDrawingCacheEnabled(true); Bitmap b = imageViewgetDrawingCache(); int w = bgetWidth(); int h = bgetHeight(); 或者也可以像下面这样:imageViewsetDrawingCacheEnabled(true); Bitmap b = imageViewgetDrawingCache(); int w = bgetWidth(); int h = bgetHeight(); 上面的代码仅仅可以为你获取当前ImageView的大小:imageViewgetWidth(); imageViewgetHeight(); 如果你要获取Drawable image对象的大小,可用如下代码:Drawable d = getResources()getDrawable(Rdrawableyourimage); int h = dgetIntrinsicHeight(); int w = dgetIntrinsicWidth();
以上就是关于小程序 image组件,高度自适应全部的内容,包括:小程序 image组件,高度自适应、Android知识点——Glide获取图片宽高、C++ 获取图片宽高等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)