本文介绍了调整相对布局中的浮动按钮位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是有一个简单的问题,但不幸的是我无法自己解决这个问题.
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.
提前谢谢.
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>
推荐答案
视图不能显示在其父级的边界之外.
A view cannot be displayed beyond the boundaries of its parent.
您可以使用FrameLayout.通过适当的位置和顺序,将浮动按钮和相对布局放到内部.
You can use a FrameLayout. Put inside your floating button and your relative layout with appropriate positioning and ordering.
这篇关于调整相对布局中的浮动按钮位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!