日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Android测量图像中物体大小,android – 加载图像后测量ImageView

發布時間:2025/3/12 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android测量图像中物体大小,android – 加载图像后测量ImageView 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我試圖找到一種方法來測量ImageView后使用Glide或Picasso(或其他任何東西)加載圖像.基本上,我試圖在某些位置在圖像頂部布局其他視圖,但需要最終的ImageViews尺寸才能準確地完成.

我不知道用于嘗試這樣做的最佳布局是什么,但我目前正在使用這個:

android:layout_width="wrap_content"

android:layout_height="wrap_content">

android:id="@+id/viewingImageView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

并將圖像加載到viewingImageView中.這些都在根FrameLayout內部,但我不認為這很重要.

這是我最近的嘗試,但是作為評論,在ImageView上使用.getWidth()和.getHeight()返回0.資源的寬度/高度返回原始圖像的大小.

滑行

.with(this)

.load(entry.getImageUrl())

.asBitmap()

.into(new SimpleTarget() {

@Override

public void onResourceReady(Bitmap resource, GlideAnimation super Bitmap> glideAnimation) {

mImageView.setImageBitmap(resource);

int width = mImageView.getMaxWidth(); //prints 0

int height = mImageView.getMaxHeight(); //prints 0

int resw = resource.getWidth(); //returns original image width

}

});

那么如何加載圖像然后在加載圖像后測量ImageView(或其包裝FrameLayout)?或者如果可能的話,測量最終布局圖像的尺寸會更好,因為我知道圖像并不總是根據比例類型填充整個ImageView.我對任何解決方案持開放態度,以上只是我迄今為止所嘗試的內容.

解決方法:

您應該等待繪制視圖,您可以像這樣使用OnGlobalLayoutListener

ViewTreeObserver vto = mImageView.getViewTreeObserver();

vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

@Override

public void onGlobalLayout() {

this.mImageView.getViewTreeObserver().removeGlobalOnLayoutListener(this);

// Get the width and height

int width = mImageView.getMeasuredWidth();

int height = mImageView.getMeasuredHeight();

}

});

標簽:android-glide,android,android-layout,picasso,imageview

來源: https://codeday.me/bug/20190824/1706670.html

總結

以上是生活随笔為你收集整理的Android测量图像中物体大小,android – 加载图像后测量ImageView的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。