2015-04-14 86 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>