How can i position a button in between two layouts

relative layout
constraint layout
android add view on top of another view programmatically
android:layout_below
frame layout in android
constraint layout in android tutorials point
android align button bottom relativelayout
how to change position of button in android studio

I am trying to position a button in between two layouts.

Also, I don't want to have to do this with a margin if I can help it, when you start dealing with different screen sizes margin breaks down. (In this image, I am trying to position the green button in between two layouts)

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:background="@color/busy_white">

    <LinearLayout
        android:orientation="vertical"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:gravity="center">

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/profile_default_round"
            android:background="@drawable/ring_status_clock_in"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="John Doe"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Manager"/>

    </LinearLayout>

    <RelativeLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/translucent_black_90"
        android:padding="16dp">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_alignParentLeft="true">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Today Total"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="08:32"/>

        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:layout_alignParentRight="true">

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Week Total"
                android:gravity="right"/>

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="24:32"
                android:gravity="center"/>

        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="-40dp">

        </LinearLayout>

        </RelativeLayout>

    <include layout="@layout/dashboard_clock_in_button" />

</LinearLayout>

This kind of UI calls for overlap of multiple layers. So FrameLayout is the hero here. To give a basic idea of what we wish to achieve, we can sketch the screen and decide placements FL is the main container which will be a FrameLayout. You need to make a button of fixed height. Let's say BL is of height bl dp. Simply provide a MarginBottom of length bl/2 dp to the LinearLayout LL. Where LL is the container which would contain the profile image and the works.

The layout file will look like this

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <LinearLayout
        android:id="@+id/ConcernedPortionofScreen"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.4"
        android:orientation="vertical">

        <!-- Parent FrameLayout 'FL' -->
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <!-- This is Layout 'LL'
                 This is where you will place your image & the nice bg
            -->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginBottom="25dp"
                android:background="#b2ebf2" />

            <!-- BL = 50dp -->
            <Button
                android:layout_width="100dp"
                android:layout_height="50dp"
                android:layout_gravity="bottom|center_horizontal"
                android:background="#558b2f"
                android:text="@android:string/ok"
                android:textSize="18sp"
                android:textColor="@android:color/white" />
        </FrameLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/RestofScreen"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.6"
        android:orientation="vertical" />

</LinearLayout>

The output will look like this

Android: how to make it no space between 2 button in a horizontal , How do you put a space between two buttons horizontally on Android? inline-block has a benefit (if not more) over float as you do not need a clearing element after the floated ones, if needed. A con of using inline-block though is that if you have your elements in your source on separate lines it will add a whitespace between your elements.

I think you should try using a RelativeLayout in which you will put your two layouts and your button. But if you want to put the button on top of the two layouts you have to put it in your RelativeLayout last because of the z-order, and then use the XML attribute android:centerInParent.

So your layout would be something like the following:

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

    <LinearLayout ...
        android:id="@+id/myLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" > <!-- Or wherever you want to position this layout -->
        ...
    </LinearLayout>
    <LinearLayout ...
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/myLayout1" > <!-- Or wherever you want to position this layout -->
        ...
    </LinearLayout>
    <Button ...
        android:layout_centerInParent="true" />
</RelativeLayout>

Which is the best layout in android we can use to design the UI , this has to be changed to the left values. In your document, select the object with which you want to work, switch to the “Layout” menu, and then click the “Position” button. That button also appears on the “Format” menu of the Ribbon and works the same way. The Position drop-down menu is divided into two sections: “In Line With Text”

You can easily implement this by using Coordinator layout.We have to specify multiple layouts one by one and the both layout must be LinearLayout . Now we have to use layout_anchor attribute inside Button

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <LinearLayout
                    android:id="@+id/LinearLayout1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="horizontal"
                    android:background="#CDDC39"
                    android:layout_weight="50"/>

                <LinearLayout
                    android:id="@+id/LinearLayout2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="horizontal"
                    android:layout_weight="50"
                    android:background="#C6FF00"
                    />

            </LinearLayout>

            <Button
                android:id="@+id/button"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                app:layout_anchor="@id/LinearLayout1"
                app:backgroundTint="#2196F3"
                app:elevation="7dp"
                android:text:"click Me"
                android:layout_margin="20dp"
                android:src="@android:drawable/ic_dialog_email"
                app:layout_anchorGravity="bottom|center" />

        </android.support.design.widget.CoordinatorLayout>

xml - Android position button in center between 2 layouts, or a custom layout instead. Those layouts will adapt to different screen sizes, whereas AbsoluteLayout will not. worked for me to align TWO Elements in a relative layout where you want the two elements to be centered around the center line.put in a horizontal linear with gravity = center and then put your controls inside that linear layout – lepert Sep 20 '13 at 1:18

Relative Layout, Use LinearLayout with vertical orientation and weightSum = "3" as Parent Layout, then add 3 child in it, Sequence should be. 1) RelativeLayout. 2) Button. The pady puts some space between the button widgets and the borders of the frame and the borders of the root window. okButton.pack(side=RIGHT) The okButton is placed next to the closeButton with 5 px space between them. Figure: Buttons example Review example. The pack manager is a simple layout manager. It can be used to do simple layout tasks.

Constructing View Layouts, RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling  Hi, Has anyone tried the layout (on your left) using Xamarin.Forms? I've started using Grid with two (2) rows.First row contains a SearchBar and a ListView in a StackLayout, and the 2nd row contains another StackLayout containing summary information.

Microsoft Office 2013: Illustrated, Second Course, are used to display child controls, such as text controls or buttons on the screen. You can create linear layouts now with ConstraintLayout by constraining the RelativeLayout positions views based on a number of directional attributes:. Some layout managers automatically put space between components; others do not. Some let you specify the amount of space between components. See the how-to page for each layout manager for information about spacing support. Invisible components. You can create lightweight components that perform no painting, but that can take up space in the GUI.

Comments
  • You need to have your two layouts and button nested in a relative layout
  • Hey bro, Did you manage to solve that problem?
  • I have not solved it yet! I did have some tell my to try Frame Layouts, but I have not got around to trying it yet. I am hopping to see support for it in Android L.
  • Thanks a lot... With slight modifications it worked for my use case :)
  • Hey guys i am having problem using this that i used this code inside scrollbar now "rest of screen" getting problem in my last item object its not showing . is there any solution regarding that ?
  • android:layout_centerInParent="true" only center it within the layout it does not let you center in between the layers.
  • Ok sorry I didn't understand your question well. You can try to put your Button below your first layout and then set a negative android:layout_marginTop. And then position your second layout below your first layout. (but again if you want your button to be on top of both you have to put it last in your RelativeLayout) I'm not sure there is a way to do it without using margins. But you can set up different values for the margin in your values-xxx folders.