2015-04-14 88 views
3

我爲我的一些屏幕創建了android layout xml,顯然我在我的應用程序中使用了導航抽屜,這就是爲什麼我使用框架佈局。現在,我已經添加了一個線性佈局,將顯示如下:將元素放置在Framelayout中具有Linearlayout的其他元素下方

有一個文本視圖提交按鈕

2圖像按鈕

這是我想要什麼樣的佈局:

enter image description here

問題是,當我做了我的佈局,我似乎無法拉下2個按鈕,使他們低於提交,因爲會發生什麼是兩個按鈕位於佈局的右側,像這樣:

enter image description here

這是我的XML代碼:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="mypackage.test.HomeActivity" > 

    <FrameLayout 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <LinearLayout 
      android:id="@+id/linerlayout" 
      android:layout_width="match_parent" 
      android:layout_height="100dp" 
       android:gravity="center_horizontal" 

      > 
        <EditText 
      android:id="@+id/editText1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:hint="Enter ID" 
      > 

      <requestFocus /> 
     </EditText> 

      <Button 
       android:id="@+id/button1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Submit" /> 
     <!-- 
     I'm trying to put the two buttons here but what happens is they both disappear when I put them 

     -->  

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

     <Button 
      android:id="@+id/button3" 
      android:text="Button" 
android:layout_width="wrap_content" 
       android:layout_height="wrap_content"/>   
     </LinearLayout> 

     </FrameLayout> 

    <fragment 
     android:id="@+id/navigation_drawer" 
     android:name="mypackage.test.NavigationDrawerFragment" 
     android:layout_width="@dimen/navigation_drawer_width" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     tools:layout="@layout/fragment_navigation_drawer" /> 
</android.support.v4.widget.DrawerLayout> 

如何拉兩個按鈕往下走?我應該將按鈕轉移到另一種佈局嗎?

回答

2

您可以將其他兩個按鈕放在LinearLayout佈局之外,這樣它們的 將出現在底部。就像這樣:

<FrameLayout 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
     android:id="@+id/linerlayout" 
     android:layout_width="match_parent" 
     android:layout_height="100dp" 
     android:gravity="center_horizontal" 

     > 
     <EditText 
      android:id="@+id/editText1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:hint="Enter ID" 
      > 
     <requestFocus /> 
     </EditText> 
     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Submit" /> 

    </LinearLayout> 

    <Button 
     android:id="@+id/button3" 
     android:text="Button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right|bottom"/> 

    <Button 
     android:id="@+id/button2" 
     android:text="Button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right|center_vertical"/> 

</FrameLayout> 
+0

我試着將它們放在外面,但它導致所有其他元素的走出去的地方的FrameLayout裏面。 – marchemike

+1

請使用我發佈的代碼,因爲我在Android Studio中嘗試過,似乎沒關係。 –

+0

我明白了。我試圖移動我的而不檢查整個代碼。現在會測試它。 – marchemike

0
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="mypackage.test.HomeActivity"> 

    <FrameLayout 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

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

      <EditText 
       android:id="@+id/editText1" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_toLeftOf="@+id/button1" 
       android:ems="10" 
       android:hint="Enter ID"> 

       <requestFocus /> 
      </EditText> 

      <Button 
       android:id="@+id/button1" 
       android:layout_width="wrap_content" 
       android:layout_height="48dp" 
       android:layout_alignParentRight="true" 
       android:text="Submit" /> 


      <Button 
       android:id="@+id/button3" 
       android:text="Button" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/editText1" 
       android:layout_alignRight="@+id/editText1" /> 

      <Button 
       android:id="@+id/button2" 
       android:text="Button" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/button3" 
       android:layout_alignRight="@+id/button3" /> 
     </RelativeLayout> 
    </FrameLayout> 

    <fragment 
     android:id="@+id/navigation_drawer" 
     android:layout_width="@dimen/navigation_drawer_width" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     tools:layout="@layout/fragment_navigation_drawer" /> 
</android.support.v4.widget.DrawerLayout>