Same DPI but different inch size

I know that the Internet is overloaded with questions about DPI px inches and so on. But after hours of browsing the Internet, my situation does not seem to happen to anyone else!

I have 2 custom builds with android studio which are mdpi. BUT one device has 3.65 inches and the other device is 10.1 inches.

I created a folder with 2 images 250x125 with a resolution of dpi 160 dpi

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

Well, it looks like the images remain the same size and don’t look @ how many inches on the device

So that everything is clear: What do I need to change in my resources or my code so that my layout is the same for different Inch sizes?

This is my good layout for my mdpi 10.1 tablet: enter image description here

This is my bad layout for my mdpi 3.65 device enter image description here

How can I make sure that even on a 3.65-inch screen, the buttons are scaled to the same PROPORTIONS as 10.1. Not inches ... not pixels ... proportions ....

This is my xml file

<?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 ... Thanks in advance

+4
source share
3 answers

There is no need to develop two xml layouts.

You can use Dimension for the field and padding according to the device.

You set a static value for the field.

dimen.xml .

layout.xml .

android:layout_marginLeft="@dimen/margin_button"

dimen.xml:

-MDPI
-
-xhdpi
-xxhdpi
-sw600dp

dimen.xml .

dimen.xml , , :

-MDPI

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

-

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

.

+3

, ...

250x125 - 250 125 .

160 dpi - , 1 = 160 .

, , , 250 1.5625 . "" . 3,65 " - , .

, , :

  • 2 ( ). mdpi, hdpi, xhdpi .. , .

  • "" LinearLayout, , . .

  • - DisplayMetrics, .

, , , , , ( ). .

+3

. - @Iacs , .

, /res , "layout". : layout-large, layout-xlarge, layout-small ..... .xml ...

Here's how things look now in my Android studio, pay attention to the layout folder structure:

And now, of course, my 2 devices with the same DPI, but with a different screen size, show my buttons the way I want them to show!

0
source

Source: https://habr.com/ru/post/1614918/


All Articles