2011-03-02 70 views
0

基本上我想在這個相關佈局中添加一個textView,微調器和一個按鈕。看起來像:Relativelayout中的按鈕被拉伸

---- ---- TextView的

-----微調----

------------ button--

問題是右下角的按鈕被拉伸,按鈕高度代表所有剩餘的空間。

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/surveyLayout" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="20dp" 
    android:layout_marginTop="20dp" 
    android:layout_alignParentTop="true" 
    android:text="@string/selectSurvey" 
    android:textColor="@android:color/darker_gray" 
    android:id="@+id/hasSurveyLabel" 
    /> 
<Spinner 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/surveySpinner" 
    android:layout_below="@+id/hasSurveyLabel" 
    /> 
<Button 
    android:layout_width="wrap_content" 
    android:layout_height="30dp" 
    android:id="@+id/startButton" 
    android:text="@string/start" 
    **android:layout_below="@+id/surveySpinner"** 
    android:layout_alignParentRight="true" 
    android:layout_alignParentBottom="true" 
    android:paddingTop="10dp" 
    android:paddingLeft="30dp" 
    android:paddingRight="30dp" 
    /> 

看起來是因爲layout_below的,當我們使用layout_below,下面微調按鈕,它必須是它下面,沒有空間,除非你定義它。
我們該如何解決這個問題?
我期待的是,把按鈕放在微調器下面,並在屏幕的底部。
我一直在這方面掙扎多日,有什麼幫助?謝謝。

+0

任何人都可以在這裏幫助? – Usher 2011-03-07 02:38:52

回答

2

我將刪除對微調框的引用,並將它放在右下角。我有一個類似的屏幕布局,以下按鈕設置適用於我。

<Button 
    android:id ="@+id/testButton" 
    android:text="Testing" 
    android:layout_width ="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight ="true" /> 

或者我所看到的做法是將它放在放置在底部的LinearLayout中。但是這種分層對我來說似乎不需要。希望這可以幫助!

<LinearLayout 
     android:orientation ="horizontal" 
     android:layout_width ="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight ="true"> 

     <Button 
     android:id ="@+id/testButton" 
     android:text="Testing" 
     android:layout_width ="wrap_content" 
     android:layout_height="wrap_content" /> 

    </LinearLayout> 
+0

我之前也嘗試過第一個解決方案,但是當您更改方向時,該按鈕將被裁剪。 – Usher 2011-04-13 19:25:36

+0

第二種解決方案適用於我。謝謝! – Usher 2011-04-13 19:25:59

0

只有高度伸展嗎?如果是這樣,我會刪除android:layout_alignParentBottom="true",只讓它引用微調,並將其對齊到右側...

+0

但按鈕不會在底部.... – Usher 2011-04-13 19:26:25