【问题标题】:Android ImageView resize height without loading image (like instagram, facebook)Android ImageView 在不加载图像的情况下调整高度(如 instagram、facebook)
【发布时间】:2018-11-17 02:43:08
【问题描述】:

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

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

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

【问题讨论】:

  • 如果您从服务器加载图像,请让您的服务器发送图像的高度/宽度。如果您动态加载图像,则没有其他方法可以知道图像的大小
  • 我认为,您必须修复 ImageView 的最小高度。
  • 我得到了 Resminence 的高度和广度。但是当宽度为 match_parent 时,高度不起作用。我如何设置在每台设备上工作。 @PankajKumar
  • 您从服务器获取图像的格式。
  • 我得到的是图片格式。使用 Glide 库。 @HemantN.Karmur

标签: android imageview height


【解决方案1】:

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

那么,你肯定会通过将图片的路径/URL转换成Bitmap来获取图片的高度和宽度。

试试这个:

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);
}

【讨论】:

  • 收到了吗? @Mehmet Kurtgoz
  • 其实这不是我想要的。因为我想在不连接互联网的情况下处理高度和宽度。如果我要连接,我会让它变慢。
  • 所以,首先请详细说明你想做什么。
猜你喜欢
  • 2016-10-09
  • 2013-06-15
  • 1970-01-01
  • 2011-08-26
  • 1970-01-01
  • 1970-01-01
  • 2010-12-19
  • 2013-03-16
  • 2015-03-13
相关资源
最近更新 更多