DPI相同,但英寸尺寸不同 [英] Same DPI but different inch size

查看:70
本文介绍了DPI相同,但英寸尺寸不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道Internet上充满了有关DPI px英寸等问题的信息.但是经过几个小时的搜寻之后,其他任何人似乎都没有遇到我的情况!

I know the Internet is overwhelmed with questions about DPI px inches and so on. But after several hours of googling my situation doesnt seem to happen to anyone else!

我有2个使用android studio自定义构建的设备,都是mdpi.但是其中一台设备是3.65英寸,另一台设备是10.1英寸.

I have 2 devices custom build with android studio which are both mdpi. BUT one device is 3.65inch and the other device is an 10.1 inch.

我创建了一个包含2张图片的文件夹,分辨率为250x125,且dpi设置为160 dpi

I have created a folder with 2 images 250x125 with the dpi set to 160 dpi

如果通常我会用dp单位而不是像素在XML中声明我的2个图像...我想在两个屏幕上结果应该是正确的吗?

If normally I would declare my 2 images in my XML with dp units instead of pixels...I would suppose on both screens the result should be the same right ?

看起来图像保持不变,看起来也不像设备有多少英寸

Well it seems the images keep remaining the same size and don't look @ how many inch the device is

所以要弄清楚:我必须在资源或代码上进行哪些更改,以使布局针对不同的英寸尺寸进行相同缩放?

So to set things clear: What do I have to change at my resources or my code so that my layout scales identical for different Inch sizes ?

这是我的mdpi 10.1平板电脑的良好布局:

This is my GOOD layout for my mdpi 10.1 tablet :

这是我的mdpi 3.65设备的BAD布局

This is my BAD layout for my mdpi 3.65 device

我如何做到这一点,即使在3.65英寸的屏幕上,按钮也将缩放到与10.1相同的比例.不是英寸...不是像素...是比例......

How can I make it so that even on the 3.65 inch screen the buttons will scale to the same PROPORTIONS as the 10.1. Not the inches...not the pixels...the proportions....

这是我的XML文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:gravity="center">

    <Button
        android:id="@+id/buttonEnglish"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/english"
        android:layout_marginBottom="5sp"
        android:layout_marginLeft="5sp"
        android:layout_marginRight="2sp"
        android:layout_marginTop="0sp" />
    <Button
        android:id="@+id/buttonNederlands"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/nederlands"
        android:layout_marginBottom="5sp"
        android:layout_marginLeft="20sp"
        android:layout_marginRight="5sp"
        android:layout_marginTop="0sp"
        />
</LinearLayout>

我很拼命...提前感谢

I'm desperate... Thanx in advance

推荐答案

无需设计两个xml布局.

There is no need of Designing two xml layout.

您可以根据设备使用Dimension进行边距和填充.

You can use Dimension for margin and padding according to device.

您为保证金提供了静态价值.

You are giving static value for margin.

在每个设备的值文件夹中使用dimen.xml.

Use dimen.xml in value folder each device.

您在layout.xml中的以下代码将为您工作.

android:layout_marginLeft="@dimen/margin_button"

dimen.xml的值文件夹名称:

values-mdpi
值-hdpi
值-xhdpi
值-xxhdpi
值-sw600dp

values-mdpi
values-hdpi
values-xhdpi
values-xxhdpi
values-sw600dp

在每个值文件夹中创建dimen.xml.

在dimen.xml中,您必须在所有values文件夹中为margin定义值,但是该属性的值根据设备大小而不同,如下所示:

and in dimen.xml you have to define value for margin in all values folder but value of that property is different according to device size like this:

values-mdpi

values-mdpi

<dimen name="margin_button">20dp</dimen>

values-hdpi

values-hdpi

<dimen name="margin_button">23dp</dimen>

在所有值文件夹中都一样.

like wise in all values folders.

这篇关于DPI相同,但英寸尺寸不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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