【问题标题】:Android, How to fit an image into screen?Android,如何将图像放入屏幕?
【发布时间】:2012-02-25 12:39:22
【问题描述】:

我需要减小当前为 40M 的 apk 文件的大小。这个尺寸是因为一些高质量的图像。因此,我决定将这些图像传输到服务器并从那里加载它们。

我创建了一些 html 网页并将每个图像放在自己的网页中。在应用程序中,我使用 webview 打开该链接并显示图像。但是,图像大于屏幕尺寸。以前因为我使用图像视图,我可以将其适应屏幕,但现在,我不确定是否可以将网页绑定到屏幕大小。

如果你知道,请指导我。谢谢

【问题讨论】:

  • 我不了解网页..但也有其他解决方案,例如将图像移动到服务器并在运行时解析它,或者第一次解析所有图像并存储在 sdcard 中然后使用..

标签: android image screen


【解决方案1】:

为什么不使用 ImageView?

只需从流中创建一个可绘制对象并在您的 ImageView 中使用它。

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet request = new HttpGet(urlString); //urlString - url of your image
HttpResponse response = httpClient.execute(request);
InputStream is = response.getEntity().getContent();

Drawable drawable = Drawable.createFromStream(is, "image");

imageView.setImageDrawable(drawable);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-24
    • 1970-01-01
    • 2012-06-17
    • 1970-01-01
    • 2011-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多