0

My XML file is :

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="mybitchinapp.cortana.com.musica.MainActivity"
    tools:showIn="@layout/app_bar_main"
    android:weightSum="7"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        >
        <LinearLayout
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:id="@+id/layout_upper"
            android:layout_weight="3"
            android:layout_marginRight="0dp"
            android:layout_marginLeft="0dp"
            android:layout_marginTop="0dp"
            android:layout_marginBottom="0dp"
            android:background="#727272">
            <android.support.v7.widget.CardView

                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/cardview"
                android:layout_marginRight="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="16dp"
                >

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:id="@+id/song_imgview"/>

            </android.support.v7.widget.CardView>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="4"
            android:id="@+id/layout_lower"
            android:orientation="vertical"
            android:background="#ffffff">

        </LinearLayout>
    </LinearLayout>
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"

        android:src="@android:drawable/ic_dialog_email"
        app:layout_anchor="@id/layout_upper"
        app:layout_anchorGravity="bottom|right|end"
        android:elevation="15dp"
        android:layout_alignBottom="@id/layout_upper"
        android:layout_marginBottom="-32dp"
        android:layout_margin="16dp"
        />

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

I am following this question's accepted answer to centre the button between two layouts: How can I add the new "Floating Action Button" between two widgets/layouts

In my output, the button is below the first linearLayout instead of between them. How do I bring it in the center ?

Community
  • 1
  • 1
kneelb4darth
  • 305
  • 3
  • 14

1 Answers1

1

You could use AppBarLayout too instead of these LinearLayouts btw:

<android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@id/layout_upper"
        android:layout_gravity="center"
        android:layout_margin="16dp"
        android:layout_marginBottom="-32dp"
        android:elevation="15dp"
        android:src="@android:drawable/ic_dialog_email"
        app:layout_anchor="@id/layout_upper"
        app:layout_anchorGravity="center|bottom" />
ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108