2010-04-23 157 views
2

我只是無法在屏幕底部顯示按鈕。我將2個textviews和2個edittext設置爲已刪除,並且當用戶單擊複選框時它們變得可見。只有這樣,我的按鈕才能正確定位,否則它會在我的應用程序啓動時位於應用程序的頂部。(請參閱:http://www.shrani.si/f/3V/10G/4nnH4DtV/layoutproblem.png) 我也嘗試了android:layout_alignParentBottom =「true」,但這也沒有幫助。Android相對佈局問題

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollview" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" android:layout_height="wrap_content"> 


<TextView android:id="@+id/txt1" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:text="Krajevna skupnost: " 
    android:layout_alignParentTop="true" /> 

<Spinner 
    android:id="@+id/spinner1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:prompt="@string/ks_prompt" 
    android:layout_below="@id/txt1"  
/> 

<TextView android:id="@+id/txt2" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:text="Zadeva: " 
    android:layout_below="@id/spinner1" /> 

<Spinner 
    android:id="@+id/spinner2" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:prompt="@string/pod_prompt" 
    android:layout_below="@id/txt2" 
/> 
<TextView android:id="@+id/tv1" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:text="Zadeva: " 
    android:layout_below="@id/spinner2" /> 

<EditText android:id="@+id/prvi" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:layout_below="@id/tv1" /> 
<TextView android:id="@+id/tv2" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:layout_below="@id/prvi" 
    android:text="Vsebina: " /> 
<EditText android:id="@+id/drugi" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:layout_below="@id/tv2" /> 

    <CheckBox android:id="@+id/cek" android:text="Obveščaj o odgovoru" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" 
    android:layout_below="@id/drugi" /> 

<TextView android:id="@+id/tv3" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:layout_below="@id/cek" 
    android:text="Email: " 
    android:visibility="gone"/> 
<EditText android:id="@+id/tretji" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:layout_below="@id/tv3" 
    android:visibility="gone" /> 

    <TextView android:id="@+id/tv4" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:layout_below="@id/tretji" 
    android:visibility="gone" 
    android:text="Telefon: " /> 

<EditText android:id="@+id/cetrti" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:visibility="gone" 
    android:layout_below="@id/tv4" /> 


    <Button android:id="@+id/gumb" 
    android:text="Klikni" 
    android:typeface="serif" android:textStyle="bold" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:layout_below="@id/cetrti" /> 

      </RelativeLayout> 

      </ScrollView> 

回答

0

我跑IT運2.1裝置 - 它看起來不錯,因爲它是。按鈕位於複選框下方。所以我不確定問題是什麼。 作爲一個可以肯定工作的快速修復 - 將相對佈局更改爲LinearLayout。它有點貴,但爲了你的目的,IMO應該工作

+0

I認爲他想要獲得屏幕底部的按鈕。 – 2010-04-23 19:00:01

+0

問題是他想讓這個按鈕與內容滾動還是不滾動?通過他的佈局設計,他希望整個佈局能夠滾動,包括按鈕。 – 2010-04-23 19:44:29

+0

我在1.6模擬器上試過我的代碼,它工作正常。問題在1.5。然後我改變我的佈局線性(內滾動視圖),現在一切都很好。 謝謝你們的迅速回復。 – DixieFlatline 2010-04-24 07:39:04

1

刪除ScrollView並將android:layout_alignParentBottom =「true」設置爲您的底部按鈕。還要刪除這一行:android:layout_below =「@ id/cetrti」。 如果你真的需要了滾動,你可以把這樣的事情:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <ScrollView 
     ... 
     <RelativeLayout 
      ... 
     </RelativeLayout> 
    </ScrollView> 
    <Button 
     android:layout_alignParentBottom="true" 
     ... 
</RelativeLayout> 
+0

不幸的是,在RelativeLayout中的android:layout_height =「wrap_content」不適用於設置爲android:layout_alignParentBottom =「true」的子組件但它似乎基本上將高度設置爲fill_parent。) 請參閱RelativeLayout文檔,其中明確提到此不支持: http://developer.android.com/reference/android/widget/RelativeLayout.html – 2011-04-10 19:03:39