福建省建设工程执业注册管理中心网站,河北省建设项目信息网站,深圳网站制作必选祥奔科技,aipage网站建设我试图找到一种方法来测量ImageView后使用Glide或Picasso(或其他任何东西)加载图像.基本上,我试图在某些位置在图像顶部布局其他视图,但需要最终的ImageViews尺寸才能准确地完成.我不知道用于尝试这样做的最佳布局是什么,但我目前正在使用这个#xff1a;android:layout_width…我试图找到一种方法来测量ImageView后使用Glide或Picasso(或其他任何东西)加载图像.基本上,我试图在某些位置在图像顶部布局其他视图,但需要最终的ImageViews尺寸才能准确地完成.我不知道用于尝试这样做的最佳布局是什么,但我目前正在使用这个android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:idid/viewingImageViewandroid:layout_widthwrap_contentandroid:layout_heightwrap_content/并将图像加载到viewingImageView中.这些都在根FrameLayout内部,但我不认为这很重要.这是我最近的尝试,但是作为评论,在ImageView上使用.getWidth()和.getHeight()返回0.资源的宽度/高度返回原始图像的大小.滑行.with(this).load(entry.getImageUrl()).asBitmap().into(new SimpleTarget() {Overridepublic void onResourceReady(Bitmap resource, GlideAnimation super Bitmap glideAnimation) {mImageView.setImageBitmap(resource);int width mImageView.getMaxWidth(); //prints 0int height mImageView.getMaxHeight(); //prints 0int resw resource.getWidth(); //returns original image width}});那么如何加载图像然后在加载图像后测量ImageView(或其包装FrameLayout)或者如果可能的话,测量最终布局图像的尺寸会更好,因为我知道图像并不总是根据比例类型填充整个ImageView.我对任何解决方案持开放态度,以上只是我迄今为止所尝试的内容.解决方法:您应该等待绘制视图,您可以像这样使用OnGlobalLayoutListenerViewTreeObserver vto mImageView.getViewTreeObserver();vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {Overridepublic void onGlobalLayout() {this.mImageView.getViewTreeObserver().removeGlobalOnLayoutListener(this);// Get the width and heightint width mImageView.getMeasuredWidth();int height mImageView.getMeasuredHeight();}});标签android-glide,android,android-layout,picasso,imageview来源 https://codeday.me/bug/20190824/1706670.html