Android: Why a simple layout test on Nexus One and Galaxy Nexus give different result? -


i'm new in android. have create simple example test scaling function of android on nexus 1 , galaxy nexus.

this layout:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/sfondo" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context="com.example.testlayout.mainactivity$placeholderfragment" >  <textview     android:id="@+id/textview1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_alignparenttop="true"     android:layout_marginleft="30dp"     android:layout_margintop="22dp"     android:text="@string/hello_world" />  <textview     android:id="@+id/textview2"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_below="@+id/textview1"     android:layout_marginleft="16dp"     android:layout_margintop="75dp"     android:layout_torightof="@+id/textview1"     android:text="@string/hello_world" />  <textview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignleft="@+id/textview1"     android:layout_centervertical="true"     android:text="@string/hello_world" />  </relativelayout> 

using particular background image specific text positions, have positions of text correct in 1 device , not in other.

this 2 phones in same layout category: normal.

why 2 different results?(also using dp) how can have same result in both devices? thanks

with dp ensure physical size of views , of margins same on devices.

that means if use background image fills whole screen, , have devices different screen size, locations on image of views different each device.

small example:

take 10cm screen, 160 dp. use margin in dp physically result in 1 cm margin (10% of screen).

now take 20cm screen, 160dp. same margin in dp, pysically still 1cm, 5% of screen. physical size of background double of size has on 10cm screen, positioning off.

one solution problem positioning in code, can scale based on available pixels of screen, i'd not recommend use such background image needs absolute positioning of views on it.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -