Rebooting
Rebooting

Reputation: 2938

android xml design construction

I am designing an app in xml android. I have been using lots of drawable resources. The thing is, when i test the design in an emulator of size 800x800 it runs fine. but as i decrease the size of the emulator to 500x500 the design starts breaking out. Its not completely in the same position. I have used a lot of layout_margin attributes. please tell if there is any other way by which my design runs fine irrespective of size of the emulator!?

a snip of my code is:

<ImageView android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:id="@+id/containers"
           android:src="@drawable/containers" 
           android:paddingTop="42px" 
           android:paddingLeft="3px">
</ImageView>
<TextView android:textColor="#000000"
          android:paddingLeft="20px" 
          android:paddingTop="58px" 
          android:layout_width="wrap_content"
          android:id="@+id/current_loc"
          android:text="@string/current_loc" 
          android:layout_height="wrap_content">
</TextView>
<TextView android:textColor="#000000"
          android:paddingLeft="20px"
          android:paddingTop="109px" 
          android:layout_width="wrap_content" 
          android:id="@+id/current_loc" 
          android:text="@string/at" 
          android:layout_height="wrap_content">
</TextView>
<Button android:text="@string/time" 
        android:textColor="#000000" 
        android:id="@+id/pickTime" 
        android:layout_height="50px" 
        android:layout_width="120px" 
        android:layout_marginTop="100px"
        android:layout_marginLeft="40px">
</Button>
<Button android:text="@string/date"
        android:textColor="#000000"
        android:id="@+id/pickDate"
        android:layout_height="50px" 
        android:layout_marginTop="100px"
        android:layout_marginLeft="160px"
        android:layout_width="100px">
</Button>
<TextView android:textColor="#000000" 
          android:layout_marginLeft="260px"
          android:id="@+id/to" 
          android:layout_marginTop="110px" 
          android:layout_width="wrap_content" 
          android:text="@string/to" 
          android:layout_height="wrap_content">
</TextView>
<EditText android:textColor="#000000" 
          android:id="@+id/editText2" 
          android:layout_marginTop="97px" 
          android:layout_marginLeft="280px"
          android:layout_height="60px" 
          android:layout_width="190px"
          android:hint="@string/dest" 
          android:textSize="20px" 
          android:singleLine="True">
</EditText>
<TextView android:textColor="#000000" 
          android:paddingLeft="20px" 
          android:id="@+id/thereare"  
          android:paddingTop="180px" 
          android:layout_width="wrap_content" 
          android:text="@string/ihave" 
          android:layout_height="wrap_content">
</TextView>
<EditText android:textColor="#000000" 
          android:id="@+id/num1" 
          android:layout_marginTop="169px"
          android:layout_height="55px"
          android:layout_width="50px"
          android:layout_marginLeft="85px" 
          android:hint="2"></EditText>
<TextView android:textColor="#000000" 
          android:paddingLeft="140px" 
          android:id="@+id/female"
          android:paddingTop="180px"
          android:layout_width="wrap_content"
          android:text="@string/female" 
          android:layout_height="wrap_content">
</TextView>
<TextView android:textColor="#000000"
          android:paddingLeft="210px"
          android:id="@+id/and" 
          android:paddingTop="180px" 
          android:layout_width="wrap_content" 
          android:text="@string/and" 
          android:layout_height="wrap_content">
</TextView>

Upvotes: 0

Views: 756

Answers (4)

Raghav Chopra
Raghav Chopra

Reputation: 527

try using this code now may be it would be helpful for u

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#8B8989" android:orientation="vertical">

write down your XML in betweenthis code

</LinearLayout>

Upvotes: 1

kyuuCR
kyuuCR

Reputation: 51

To make xml design works properly on any screen device, wrap your widget around RelativeLayout and change you measurement unit from px to dp. With dp unit you will get relative measurement that change depends on the screen resolution.

For more info, refer to this link http://developer.android.com/guide/practices/screens_support.html

Upvotes: 3

Alexander
Alexander

Reputation: 48252

You should try to get rid of specifying sizes in pixels. Instead you can use dip and layout_weights

Upvotes: 2

Manos
Manos

Reputation: 2186

You can specify different layout .xml files for different screen resolutions, to avoid your problem. Read carefully the guidelines that Android Developers site gives here

Upvotes: 1

Related Questions