首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >安卓ImageView无需加载图片即可调整高度(如instagram、facebook)

安卓ImageView无需加载图片即可调整高度(如instagram、facebook)
EN

Stack Overflow用户
提问于 2018-06-07 16:50:27
回答 1查看 167关注 0票数 1

我想要做的图像是在图像视图出现在屏幕上之前获得它的形状。

<ImageView
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:scaleType="fitCenter"/>

我这样做了,但图像视图没有出现,因为在图像加载之前高度是wrap_content。图像在上传后会扩展,但我想在不加载图像的情况下获取图像大小。

EN

回答 1

Stack Overflow用户

发布于 2018-06-07 17:11:51

我假设您正在从服务器获取图像URL /路径。比如,http://.....

然后,通过将图像转换为位图,您肯定会从其路径/ URL中获得图像的高度和宽度。

试试这个:

try {

    URL url = new URL("http://....");// here put your string URL comes from server
    Bitmap image = BitmapFactory.decodeStream(url.openConnection().getInputStream());

    int width = b.getWidth(); // here is the your image width
    int height = b.getHeight(); // here is the your image height

} catch(IOException e) {
    System.out.println(e);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50736898

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档