-1

I have a problem while placing the buttons in my xml file.

This is my graphical layout

Now what I want is that the "ok" button at the bottom should come below the mileage edit text that is at the second last strip. I am using a scroll view before the button. Also I am using a single image as a background.

How is it possible that all my buttons in my application only come on the second last strip (gray color)? The rest of the layout should come in between (i.e. between top gray strip and the bottom gray strip).

I tried using margin_top or margin_bottom in 'dp' but its not coming properly plus on every other phone the layout of button changes. Here is my code (.xml file):

     <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:background="@drawable/menu"
    android:padding="10dp">

    <ScrollView
        android:id="@+id/scv"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="105dp"
        android:layout_marginBottom="105dp" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:ems="10"
        android:hint="Year"
        android:inputType="date" />

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText1"
        android:layout_alignRight="@+id/editText1"
        android:layout_below="@+id/editText1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp" />

    <Spinner
        android:id="@+id/spinner2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/spinner1"
        android:layout_alignRight="@+id/spinner1"
        android:layout_below="@+id/spinner1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp" />

    <Spinner
        android:id="@+id/spinner3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/spinner2"
        android:layout_alignRight="@+id/spinner2"
        android:layout_below="@+id/spinner2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/spinner3"
        android:layout_below="@+id/spinner3"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:ems="10"
        android:hint="Mileage"
        android:inputType="number" />
  </RelativeLayout>
         </ScrollView>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="10dp"
        android:text="OK" />

    </RelativeLayout>
Carbon
  • 133
  • 1
  • 4
  • 21

2 Answers2

0

You should never use a single image for your complete layout on Android. That just doesn't run very well as you have so many different screen sizes.

I'd recommend you cut the graphic out in portions and make it stretch so it will fit depending on the screen size. It's not really possible to help you much more based on the poorly copy paste of your own code and the lack of visualization of what you want the graphic to look like.

Warpzit
  • 27,966
  • 19
  • 103
  • 155
  • i have changed my pic (before and after) for u soo plz see and understand it and hope dis tym u find a solution – Carbon Mar 20 '13 at 09:58
0

For your button xml, try

<Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/scv"
        android:layout_centerHorizontal="true"
        android:text="OK" />

You can add android:layout_marginTop="5sp" changing the value if necessary. This will place your button below your scrollview.

Damien R.
  • 3,383
  • 1
  • 21
  • 32