tags:

views:

251

answers:

2

I am designing a home screen widget. The widget layout file is like below.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget"
android:layout_width="240dip" android:layout_height="200dip"
    android:background="@drawable/base_all"
/>

I ran this widget on a HTC Hero device, which has a screen of 320 pixels * 480 pixels with mdpi. It ran perfect on HTC Hero. The widget takes 3 cells * 2 cells space, i.e. 240 pixels * 200 pixels.

Then I ran this widget on a Nexus One device, which has a screen of 480 pixels * 800 pixels, mdpi. Since Nexus One also is mdpi, so I though 240dip is equivalent to 240 pixels on Nexus One and 200dip is equivalent to 200 pixels on Nexus One, so the widget will not take 3 cells * 2 cells space on Nexus One device. To my surprise, when running on Nexus One device, the widget take exact 3 cells * 2 cells, about 360 pixels * 300 pixels, on Nexus One device.

I am confused. The layout xml above specifies 240dip in width and 200dip in height for the widget, but why did it take 360 pixels * 300 pixels on Nexus One Device? What am I missing?

Thanks.

A: 

You are mixing device independent pixels and hardware device pixels. I don't think that's going to work out too well.

A widget that takes up 3x2 on a hero will take up 3x2 on a Nexus One. This is what I was trying to get across in my answer to your earlier question: http://stackoverflow.com/questions/2547282/home-screen-widget-size-for-large-screen-or-hdpi

mbaird
A: 

In reply to mbaird's comment:

I am still confused. Suppose I specify a ImageView, picture1, with 90dip * 100dip as below in the widget. What dimension in device pixels will the ImageView on the Nexus One device?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget"
android:layout_width="240dip" android:layout_height="200dip"
    android:background="@drawable/base_all"
>
<ImageView android:id="@+id/picture1"
    android:layout_width="90dip"
    android:layout_height="110dip"
    />
</RelativeLayout>

I have to know this, because in my program I have to draw on the ImageView:

public void draw(Canvas canvas) {
    ShapeDrawable drawable = new ShapeDrawable(new RectShape());
    drawable.getPaint().setColor(Color.WHITE);
    drawable.setBounds(m_leftTopX, m_leftTopY, m_leftTopX + m_width,
            m_leftTopY + m_height);

    drawable.draw(canvas);
}

As I understant, drawable.setBounds() is using physical pixels in its parameters. I need to know the size of the ImageView in dimension of physical pixels.

Thanks.

I figured out what's wrong.My app is targeting Android 1.5, which doesn't support large screen. So, Android os always treat large screen as 320*something screen.