0

I have an xml that have an imageView in it.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/blockingLayer"
    android:layout_width="880px"
    android:layout_height="600px">
        <ImageView 
            android:layout_width="110px"
            android:layout_height="60px"
            android:id="@+id/fish_image_view"
            android:visibility="visible"
            android:layout_marginLeft="0px"
            android:layout_marginTop="350px"
            />
</RelativeLayout> 

In code i am getting this imageView and running the translateAnimation on it from X1 = 10 to x2 = ScreenWidth , Y1 & Y2 = 350px. This animation is working fine on android version 2.2 but when i run this on OS 2.3 / 4.0 ImageView will cuttoff and disappear on some points on screen during translate animation.

I could not understand what is going wrong with this. Response will be appreciated.

Asad Iqbal
  • 304
  • 4
  • 16

1 Answers1

3

Dont use "px". Change it to "dip"

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/blockingLayer"
    android:layout_width="880dip"
    android:layout_height="600dip">
        <ImageView 
            android:layout_width="110dip"
            android:layout_height="60dip"
            android:id="@+id/fish_image_view"
            android:visibility="visible"
            android:layout_marginLeft="0dip"
            android:layout_marginTop="350dip"
            />
</RelativeLayout> 

Source from here, What is the difference between "px", "dp", "dip" and "sp" on Android?

px Pixels - corresponds to actual pixels on the screen.

dp Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".

Community
  • 1
  • 1
Andro Selva
  • 53,910
  • 52
  • 193
  • 240
  • I think, this issue is not related with screen density as i check this on different devices running Os 2.2 but it fail on other versions of OS. – Asad Iqbal Jul 13 '12 at 07:48
  • I think you don't get it. maybe your 2.2 devices are of same density and the other os device is of bigger density. And you experience the problem with that device alone. – Andro Selva Jul 13 '12 at 07:51