luQ
luQ

Reputation: 529

Adjust Floating Button Position in Relative Layout

i just have a simple question, but unfotunately Iwas not able to figure this one out on my own.

I want to position a Floating Button at the top left corner of a parent relative layout. The center of the Floating Button shall be centered at the top edge of my parent layout.

Thx in advance.

enter image description here

XML:

  <LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:orientation="horizontal"
    android:padding="75dp">

    <LinearLayout

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="25dp">

        <RelativeLayout
            android:id="@+id/fragment_formgenerator_firststep_relativelayout_first"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="25dp">


            <com.example.lukas.masterthesis.floatingactionbutton.FloatingActionButton
                android:id="@+id/fab_1"
                android:layout_width="@dimen/fab_size_small"
                android:layout_height="@dimen/fab_size_small"
                android:elevation="@dimen/fab_elevation"
                android:background="@drawable/fab_background"
                android:stateListAnimator="@animator/fab_anim"
                android:layout_gravity="center_horizontal"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true">

                <ImageView
                    android:layout_width="@dimen/fab_icon_size"
                    android:layout_height="@dimen/fab_icon_size"
                    android:src="@drawable/fab_icons"
                    android:layout_gravity="center"
                    android:duplicateParentState="true"/>

            </com.example.lukas.masterthesis.floatingactionbutton.FloatingActionButton>

            <ImageView
                android:id="@+id/fragment_newproject_imageview_add_first"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:src="@drawable/ic_newproject" />

        </RelativeLayout>
        <TextView
            android:id="@+id/fragment_newproject_textview_add_first"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:paddingTop="10dp"
            android:text="@string/fragment_newproject_add" />
    </LinearLayout>

Upvotes: 1

Views: 2131

Answers (1)

clemp6r
clemp6r

Reputation: 3723

A view cannot be displayed beyond the boundaries of its parent.

You can use a FrameLayout. Put inside your floating button and your relative layout with appropriate positioning and ordering.

Upvotes: 3

Related Questions