Reputation: 2589
I am working on a game like app in which the user has to find different Objects within the given time.
All things are working on my mobile phone but the location of the objects change when I install the same game on a different device. Basically I have chosen a background image (background of the layout) and locate the different objects on it and have to hide the object in the specific location.
Their position is different on different mobiles, I am using Eclipse and I have checked it using RelativeLayout
, LinearLayout
and linear inside the relative and vice versa throw java the code is given below
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/background2" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img1"
android:layout_marginLeft="100dp"
android:layout_marginTop="100dp" />
</LinearLayout>
Upvotes: 0
Views: 790
Reputation: 684
Instead of using
android:layout_marginTop="100dp"
you should use
android:layout_weight
the reason for this is because even if you change the orientation of your device, your app's layout will not stay consistant. For example try something like:
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_gravity="center"
android:id="@+id/tv_c"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="wrap_content" />
<TextView
android:layout_gravity="center"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="wrap_content">
</LinearLayout>
this gaurantees that no matter what the screen size, both textviews will share the screen equally.
Upvotes: 1