2013-03-20 164 views
-1

將按鈕放在我的xml文件中時出現問題。Android Xml按鈕佈局

This is my graphical layout

現在我想的是,在底部的「確定」按鈕來應該是在倒數第二條里程編輯文本的下方。我在按鈕之前使用滾動視圖。此外,我使用單個圖像作爲背景。

我的應用程序中的所有按鈕都只出現在第二個條(灰色)上怎麼可能?其餘佈局應該介於兩者之間(即在頂部灰色條和底部灰色條之間)。

我嘗試在'dp'中使用margin_top或margin_bottom,但它沒有正確加上其他手機的按鈕更改佈局。這裏是我的代碼(.xml文件):

 <?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> 
+0

scrollview和relativelayout沒有關閉標籤。這是完整的佈局代碼? – 2013-03-20 09:32:01

+0

不,我已關閉這兩個d佈局..見前按鈕代碼 – Carbon 2013-03-20 16:06:14

回答

0

你不應該在Android上使用單個圖像來完成你的佈局。由於您擁有許多不同的屏幕尺寸,所以效果不佳。

我建議你將部分圖形裁剪出來,並使其伸展,以適應屏幕尺寸。根據你自己的代碼的糟糕的複製粘貼和你想要圖形看起來缺乏可視化的方式,不可能幫助你更多。

+0

我已經改變了我的照片(之前和之後)爲你soz plz看到和理解它,並希望dis tym你找到解決方案 – Carbon 2013-03-20 09:58:17

0

對於按鈕XML,嘗試

<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" /> 

您可以添加android:layout_marginTop="5sp"如果需要更改值。 這會將您的按鈕放置在滾動視圖的下方。

+0

非常感謝..它工作! :) – Carbon 2013-03-20 10:29:16

+1

只是不要使用sp而是dp。在這裏閱讀更多:http://stackoverflow.com/a/2025541/969325 – Warpzit 2013-03-20 10:30:41

+0

感謝提示warpzit。 – 2013-03-20 10:44:27