简体   繁体   English

缩放ldpi,mdpi,hdpi和xhdpi的图像

[英]scale images for ldpi mdpi hdpi and xhdpi

i have 5 buttons with background_button image size 267x63. 我有5个按钮,background_button图像尺寸为267x63。 I have copied all background_button with resolution 267x63 in ldpi mdpi hdpi xhdpi. 我已经以ldpi mdpi hdpi xhdpi复制了所有分辨率为267x63的background_button。 When i try to run my app, button is big in 2,7" QWGA but in tablet mode is small. 当我尝试运行我的应用程序时,按钮在2,7“ QWGA中较大,但在平板电脑模式下较小。

Which is the best risolution for my background_button in ldpi mdpi hdpi and xhdpi? 在ldpi,mdpi,hdpi和xhdpi中,我的background_button最好的解决方法是什么?

xml button: xml按钮:

    <Button  
    android:id="@+id/button5"
    android:layout_width="230dp"
    android:layout_height="60dp"
    android:layout_alignLeft="@+id/textView1"
    android:layout_below="@+id/textView1"
    android:background="@drawable/a"
    android:textColor="#FFFFFF"
    android:textStyle="bold" />

if i scale background_button and set this: 如果我缩放background_button并设置为:

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

my button is strict... can you help me please? 我的按钮很严格...您能帮我吗?

Actually, you should not to place THE SAME images to all folders -ldpi, -mdpi, -hdpi. 实际上,您不应将“相同”图像放置到所有文件夹-ldpi,-mdpi和-hdpi。

Lets imagine, you want to support xxhdpi devices. 假设您要支持xxhdpi设备。 You create image for xxhdpi (for example 1Mb) and put it to all folders. 您为xxhdpi创建图像(例如1Mb)并将其放置到所有文件夹中。 And what will you get on a ldpi device? 在ldpi设备上会得到什么? Image will be scaled. 图像将被缩放。 Quality of image on the screen will be horrible. 屏幕上的图像质量将非常糟糕。 And another thing: if you want to have 100 images on a screen at the same time, each by 2-5Mb, and you create all of this images for xxhdpi devices, then you can get OutOfMemoryError on ldpi device. 还有另一件事:如果您希望同时在屏幕上显示100张图像,每张图像的大小为2-5Mb,并且为xxhdpi设备创建所有这些图像,则可以在ldpi设备上获取OutOfMemoryError。

So, the best practice is NOT to put the same images to all the folders. 因此,最佳实践是不要将相同的图像放入所有文件夹。 If you have some resolution independent images, then you can put them into drawable folder (without postfix). 如果您有一些与分辨率无关的图像,则可以将它们放入可绘制的文件夹(不带后缀)。 But you should NOT put the same images to ldpi and xxhdpi folders. 但是,您不应将相同的图像放入ldpi和xxhdpi文件夹。

So answers with resizing are terrible. 因此,调整大小的答案是可怕的。

Look at this article 看这篇文章

At "Alternative drawables" paragraph. 在“替代性可绘制项目”段落中。 On this image 在这张图片上

在此处输入图片说明

you can see that for xhdpi device you should have image 2 times larger than for mdpi. 您会看到,对于xhdpi设备,图像应比mdpi大2倍。 And so on. 等等。

Hope it helps 希望能帮助到你

You can use the following code to display according to screen resolution - 您可以使用以下代码根据屏幕分辨率进行显示-

Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).
                   getDefaultDisplay();
int screenWidth = display.getWidth();
int screenHeight = display.getHeight();

Code to resize image --- 代码以调整图像大小---

private Bitmap resizeImage( final Bitmap image) {
        Bitmap resizedImage = null;
        if(image != null)
        {
        int maxHeight = 80; //actual image height coming from internet
        int maxWidth = 150; //actual image width coming from internet

        int imageHeight = image.getHeight();
        if ( imageHeight > maxHeight )
        imageHeight = maxHeight;
        int imageWidth = (imageHeight*image.getWidth()) // image.getHeight();
        if ( imageWidth > maxWidth ) {
        imageWidth = maxWidth;
        imageHeight = (imageWidth*image.getHeight()) // image.getWidth();
        }
        resizedImage = Bitmap.createScaledBitmap( 
                       image, imageWidth, imageHeight, true);
        }
        return resizedImage;
        }

I have apps that support multiple screen sizes also, and the link that krossovochkin supplied is the best one to use. 我的应用程序也支持多种屏幕尺寸,并且krossovochkin提供的链接是最适合使用的应用程序。 However with my apps I used the following width sizes which seem to work fine and the resolutions are perfect for what I needed: 但是,在我的应用程序中,我使用了以下宽度大小,这些大小似乎很好用,并且分辨率非常适合我的需求:

ldpi - 75px (120dpi resolution) ldpi-75px(120dpi分辨率)
mdpi - 100px (160dpi resolution) mdpi-100px(160dpi分辨率)
hdpi - 150px (240dpi resolution) hdpi-150px(240dpi分辨率)
xhdpi - 200px (320dpi resolution) xhdpi-200px(320dpi分辨率)

But these all depend on what you are going to be displaying on the buttons NB: Ensure that you scale your buttons DOWN not up! 但是,所有这些都取决于您将要在按钮NB上显示的内容:确保您将按钮缩放为向下而不是向上!

Alternatively see this device display 或者查看此设备的显示

You do this wrong. 你做错了。 You cannot just put the sane image in all folders - you need to scale it correctly for each bucket. 您不能仅将健全的图像放置在所有文件夹中-您需要为每个存储桶正确缩放它。 As solution you should ie design all your graphics in one target density in mind (ie xhdpi ) and then scale it down to match bucket requirements. 作为解决方案,您应该在脑海中以一个目标密度(即xhdpi )设计所有图形,然后将其缩小以符合存储桶要求。 Since scale factor is known you can do this in many ways (also by using tools like: 9patch resizer , FRED , Drawable Resizer or others). 由于比例因子是已知的,因此您可以通过多种方式执行此操作(也可以使用以下工具: 9patch resizerFREDDrawable Resizer或其他工具)。

See this Supporting Multiple Screens article on developer site. 请参阅开发人员网站上的此“ 支持多屏”文章。

Try to use this... 尝试使用这个...

<Button  
android:id="@+id/button5"
android:layout_width="230dip"
android:layout_height="60dip"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:background="@drawable/a"
android:textColor="#FFFFFF"
android:textStyle="bold" />

You should create images of differents sizes and put them in its corresponding folders, drawable-mdpi , drawable-hdpi etc. You should not modify the values in your xml code. 您应该创建大小不同的图像,并将其放入相应的文件夹drawable-mdpidrawable-hdpi等。您不应修改xml代码中的值。 Check the article of developer.android . 查看developer.android的文章。 You need to start at a scale, for example xxxhdpi , and from there scale down your images for densities mdpi, hdpi, xhdpi, xxhdpi. 您需要从一个比例开始,例如xxxhdpi ,然后从该位置按比例缩小图像的密度mdpi,hdpi,xhdpi,xxhdpi。

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

相关问题 使用9个Patch图像而不是mdpi / ldpi / hdpi / xhdpi图像 - Use 9 Patch images instead of mdpi/ldpi/hdpi/xhdpi images 如何在 mdpi、ldpi、hdpi、xhdpi 中调整图像大小 - How to resize image in mdpi, ldpi, hdpi, xhdpi 有没有办法从大型图像创建 xxhdpi、xhdpi、hdpi、mdpi 和 ldpi 可绘制对象? - Is there a way to create xxhdpi, xhdpi, hdpi, mdpi and ldpi drawables from a large scale image? android调整所有屏幕(ldpi,mdpi,hdpi,xhdpi)的图像大小并放入文件夹 - android resizing images for all screens (ldpi,mdpi,hdpi,xhdpi) and put in folders Android中所有ldpi,mdpi,hdpi,xhdpi的单个图像 - single image for all ldpi, mdpi, hdpi, xhdpi in android 显示密度和资源使用情况(ldpi / mdpi / hdpi / xhdpi) - display density and resources usage (ldpi/mdpi/hdpi/xhdpi) 可绘制尺寸:LDPI,MDPI,HDPI,XHDPI,XXHDPI,XXXHDPI? - Sizes for drawable: LDPI, MDPI, HDPI, XHDPI, XXHDPI, XXXHDPI? 可绘制ldpi / mdpi / hdpi / xhdpi文件夹的最佳位图大小是多少? - What is the optimal bitmap size for drawable ldpi / mdpi / hdpi / xhdpi folders? 如何在Android资产文件夹中保留hdpi,mdpi,ldpi和xhdpi文件? - How to keep hdpi,mdpi,ldpi and xhdpi files in the Android asset folder? 在ldpi,mdpi,hdpi,xhdpi,xxhdpi中自动将sp相互转换 - Convert sp automatically to each other in ldpi, mdpi, hdpi, xhdpi, xxhdpi
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM