问题
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.
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>
回答1:
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.
来源:https://stackoverflow.com/questions/29672837/adjust-floating-button-position-in-relative-layout