Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Placing elements below other elements in Framelayout with Linearlayout

I created a android layout xml for some of my screens, and apparently I am using a navigation drawer in my app which is why I am using a frame layout. Now I've added a linear layout that will show the following:

A text view with a submit button

2 image buttons

This is a sample layout of what I want:

enter image description here

The problem is when I made my layout, I can't seem to pull down the 2 buttons to make them below the submit and because what happens is that both of the buttons are on the right side of the layout, like this:

enter image description here

This is my xml code:

<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>

How do I pull the two buttons to go down? Should I transfer the buttons to another layout?

like image 968
marchemike Avatar asked Apr 14 '15 23:04

marchemike


People also ask

What is the difference between FrameLayout and LinearLayout?

Definitions: Frame Layout: This is designed to block out an area on the screen to display a single item. Linear Layout: A layout that arranges its children in a single column or a single row. Relative Layout: This layout is a view group that displays child views in relative positions.

What is the default placement of objects in a RelativeLayout?

By default, all child views are drawn at the top-left of the layout, so you must define the position of each view using the various layout properties available from RelativeLayout.

How do you create a LinearLayout with view components?

To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout). Then set the android:layout_weight of each view to "1" .

Can we use linear layout in RelativeLayout inside?

We can use LinearLayout inside RelativeLayout. We can also use RelativeLayout as a Child of LinearLayout.


1 Answers

You can put the two other buttons outside of the LinearLayout layout so that they will appear on the bottom. Like this:

<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>
like image 77
Christian Abella Avatar answered Oct 29 '22 20:10

Christian Abella