2014-10-04 22 views
0

我有一個RelativeLayout的哪個includes以下的RelativeLayout:頁腳視圖RelativeLaout

<RelativeLayout 
     android:id="@+id/buttons_bar" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:paddingTop="10dip" > 

     <Button 
      android:id="@+id/day_button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="day" 
      android:layout_alignParentLeft="true" 
      android:textSize="14sp"/> 


     <Button 
      android:id="@+id/month_button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="month" 
      android:layout_alignParentRight="true" 
      android:textSize="14sp"/> 

     <EditText 
      android:id="@+id/week_button" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@id/day_button" 
      android:layout_toLeftOf="@id/month_button1" 
      android:maxLines="5" 
      android:minLines="1" 
      android:textSize="16sp" 
      android:layout_marginBottom="15dp"/> 
    </RelativeLayout> 

這種佈局將被示爲在網頁頁腳。 正如你看到EditText的maxLines是5.當EditText中的行大小大於2時,它周圍的按鈕開始移動一點點。 我想將按鈕粘到頁面的末尾,不要移動。任何解決方案

我試着爲按鈕添加android:layout_alignParentBottom="true",但它不起作用。

回答

0

它聽起來像是在UI框架中的一個錯誤,但通常都是爲了達到相同的視覺效果。

例如,將您在XML中顯示的RelativeLayout替換爲LinearLayoutorientation="horizontal"應該給出相同的視覺效果。

僞代碼

<LinearLayout horizontal> 
    <Button wrap_content layout_gravity=bottom/> 
    <EditText width=0dp weight=1/> // makes EditText fill remaining space 
    <Button wrap_content layout_gravity=bottom/> 
</LinearLayout> 
+0

只要編輯文本行超過1,按鈕向上移動。 – Ali 2014-10-04 20:54:06

+0

ops,我的不好,我在我的僞代碼中添加了兩個缺少的參數,它解決了嗎? – Budius 2014-10-04 20:56:03

+0

謝謝你的幫助。 – Ali 2014-10-04 21:01:45

1

嘗試添加 android:layout_alignParentBottom="true" 所有子元素

它至少在Android Studio中起作用。

修訂

添加android:layout_alignBottom="@+id/week_button"的兩個按鈕。

enter image description here

+0

這正是我所做的。頁腳佈局佔據了整個頁面。請注意,頁腳佈局位於另一個相對佈局中。 – Ali 2014-10-04 20:52:04

+0

@Ali檢查更新的答案 – 2014-10-04 20:59:57

+0

它也很好,謝謝。 +1爲您提供幫助。 – Ali 2014-10-04 21:21:46