0

I'm having some problems with resolution/density of android layout designs.

For example I'm using like base size in AVD 4" 480x800 hdpi (Normal-Land) and this is the result showed

enter image description here

for the same layout in AVD 7" 800x600 hdpi (Large-Land) shows like this

enter image description here

This is the layout code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/fondo_main"
    android:gravity="center"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tittle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left|center_vertical"
        android:layout_marginBottom="15dp"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="10dp"
        android:background="@color/fondo_main"
        android:text="Menu Principal"
        android:textColor="@color/azul_asde"
        android:textSize="25sp" />

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="50dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/roundcorners"
        android:gravity="center" >

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:gravity="center"
            android:orientation="horizontal" >

            <ImageView
                android:id="@+id/buttonnewreg"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:scaleType="fitCenter"
                android:src="@drawable/nuevopac3" />

            <ImageView
                android:id="@+id/buttonviewreg"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:scaleType="fitCenter"
                android:src="@drawable/verpac4" />

            <ImageView
                android:id="@+id/buttonconfig"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:scaleType="fitCenter"
                android:src="@drawable/config5" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="10dp"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/Textheadwelcome2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="Nueva ficha"
                android:textColor="@color/azul_asde"
                android:textSize="16sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/Textheadwelcome2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="Ver fichas"
                android:textColor="@color/azul_asde"
                android:textSize="16sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/Textheadwelcome2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="Configuración"
                android:textColor="@color/azul_asde"
                android:textSize="16sp"
                android:textStyle="bold" />
        </TableRow>
    </TableLayout>

</LinearLayout>

The size of images is 100x100 px and I doubt about how to choose the size in pixels of an image to use as a base for HDPI and from there increase to xhdpi or decrease to mdpi

Faced with the same category of pixel density (hdpi) as you can control the size of the images?, Because it is clear that the problem is screen resolution 480x800 against the 800x1200. In spite of 800x1200 use hdpi clearly see that the image is smaller

Thanks

Hanzo
  • 1,839
  • 4
  • 30
  • 51

1 Answers1

1

What you observe is a result of both screens having roughly the same dpi (hence usage of the same image resolutions). You will also notice that the fonts are not scaling as the 7" tablet simply has more screen space available vs the 4" phone.

It would be hard though to achieve the exact same look on all devices though. Not all devices have the same aspect ratio nor orientation for that matter.

I assume you don't want to manually set each and every screen element; perhaps you should just focus on the images themselves and fix them with android:scaleType="FIT_CENTER". This might cause some blurring due to bitmap resizing though.

An alternative could be to use vector images, such as SVG with androidSVG library to reduce blurring.

velis
  • 8,747
  • 4
  • 44
  • 64
  • How can it solve the problem that for the same density, the resolution increases too much? For example, Galaxy Nexus 10 have density XHDPI but his resolution is 2560x1600 versus the 1280x800 resolution of standard tablets of 10". Thanks – Hanzo May 13 '14 at 08:03
  • How can WHAT solve the problem? Scaling or using vector images? The problem with N10 is solved by making a version of image for XHDPI and place it in drawable-xhdpi folder (or using vector image instead). Scaling only solves the problem where you have a 7" device and a 10" device, both sporting XHDPI. – velis May 14 '14 at 07:57
  • Hi, thanks for your ask. I have a `XHDPI` of all of my images of my project, but the problem is that `Nexus 10` have `2560x1600` screen resolution maintaining `XHDPI` density (instead of `XXHDPI`) and the images in this screen resolution shows very small with `XHDPI` version. `XHDPI` images shows "correct" size in `1280x800` standard tablets. Sorry if I not explain correctly. – Hanzo May 14 '14 at 11:26
  • 1
    Yes, but if you scale them, they will appear larger, will they not? – velis May 14 '14 at 11:28
  • Ok, then How can I check if the relationship `resolution-density` is the "standard" to scale the images? – Hanzo May 14 '14 at 11:31
  • 1
    You don't. You just define the layout such that ImageViews are spaced according to available screen space (using `layout_weight` attribute), set their scaleType to FIT_CENTER and have them resize the images. Android will choose which resolution bitmap to load based on device display density. I hope I understand what you're trying to ask. – velis May 14 '14 at 11:36
  • I've edited my original post with `android:scaleType="fitCenter"` to the images and the images not resize. How can it be wrong? Thanks – Hanzo May 14 '14 at 11:47
  • FIT_CENTER, not fitCenter. Read the docs. http://developer.android.com/reference/android/widget/ImageView.ScaleType.html – velis May 15 '14 at 13:21
  • Sorry about that. But still, you can test this out in designer already, just use different scale types and you sjhould immediately see the differences they make. Apart from actually writing my own version of your layout this is about as far as I can help you with this. – velis May 19 '14 at 08:12