简体   繁体   English

在所有Android设备上显示图像

[英]Display images on all android devices

in my android application, I want to display some images of plants (i have more than 100 of them) ai also want to support different screen sizes, but my problem is i can not have images for every screen density in res/drawable folder, because size of my application horribly increase. 在我的android应用程序中,我想显示一些植物的图像(我有100多个),我也想支持不同的屏幕尺寸,但是我的问题是我无法在res / drawable文件夹中获得每个屏幕密度的图像,因为我的应用程序规模惊人地增加。 Is there any solution how to do this? 请问有什么解决办法吗? (maybe in code) Thanks a lot. (也许在代码中)非常感谢。

From what I understand, you want to have the text wrap around the image. 据我了解,您希望文本围绕图像包装。 You could best achieve this using this library . 您最好使用此库来实现。

As for the images, you would only need to store them at a size that looks good on the largest devices you are looking to support. 至于图像,您只需要将其存储在看起来要支持的最大设备上的大小即可。 For the other devices, you would just scale those down. 对于其他设备,您只需将其缩小。 If you're going to use the above library, you might need to set the following parameters on the ImageView in the XML file to have it scale down correctly: 如果要使用上述库,则可能需要在XML文件中的ImageView上设置以下参数,以使其正确缩小:

android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"

Note that you will need to fiddle around with these (especially the weight) so that you get the best fit for your application. 请注意,您将需要四处弄乱它们(尤其是重量),以便最适合您的应用程序。

EDIT : To conform to your requirement in the comment, the best way to go would be to use a WebView . 编辑 :为了符合您在注释中的要求,最好的方法是使用WebView This does mean you will need to create HTML code for your articles, which would completely change the question. 这确实意味着您将需要为文章创建HTML代码,这将完全改变问题。

What you could try is to have a LinearLayout surrounding the image and add TextView objects to it programatically. 您可以尝试在图像周围LinearLayout一个LinearLayout并以编程方式向其添加TextView对象。 There are good chances that this will look bad depending on the amount of text you will be adding. 根据您要添加的文本数量,这很有可能看起来很糟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM