如何从绘制,xhdpi图像 [英] How to get image from drawable-xhdpi

查看:117
本文介绍了如何从绘制,xhdpi图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的应用程序支持多种密度。因为我们知道,如果我们想要得到的密度值,我们使用的语法类似这样的getResources()getDisplayMetrics()密度。

I try make my application support multiple density. As we know if we want to get value of density we use syntax like this "getResources().getDisplayMetrics().density;".

我的问题是如何从一些文件夹获取图片。让说我有一个变量:

My question is how to get picture from some folder. let say i have a variable :

    float myDensity = getResources().getDisplayMetrics().density;

在myDensity返回1.0,我想从拿绘制-MDPI的画面,当它在文件夹中绘-xhdpi返回0.75我要拍照,从绘制-LDPI,并用相同的图片,和文件夹绘制-xxhdpi。我尽量做到这样
treepict.setImageResource(R.drawable-hdpi.tree); 但是我得到的只是错误

when myDensity return 1.0 , I want take picture from drawable-mdpi, when it return 0.75 i want to take picture from drawable-ldpi, and same with picture in folder drawable-xhdpi, and folder drawable-xxhdpi. i try to make it like this treepict.setImageResource(R.drawable-hdpi.tree); but that i get just error.

有人能帮助我如何做到这一点?

anyone can help me how to do this?

推荐答案

您不能设置像 R.drawable-hdpi.tree 。仅 R.drawable.tree 为每个绘制树图像创建。如果你使用 R.drawable.tree ,则系统会自动根据屏幕密度选择。

you can not set like R.drawable-hdpi.tree. only R.drawable.tree is created for every drawable tree images. if you use R.drawable.tree then system will choose automatically depending on the screen density.

现在,如果你想为diffeent分辨率,你可以使用不同的图像在你的应用程序,以显示不同的图像。

now if you want different image for diffeent resolution you can use different images to show in your app.

这篇关于如何从绘制,xhdpi图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆