我有一个 FloatingActionButton。我希望它像这样位于 2 个 LinearLayouts 的中间和屏幕中心。
目前我的设计是这样的
我希望它位于屏幕的正中央。如何做到这一点?
这是我的整个xml代码
<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/viewA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.6"
android:orientation="horizontal"/>
<LinearLayout
android:id="@+id/viewB"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:orientation="horizontal"/>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="@drawable/ic_plus"
app:layout_anchor="@id/viewA"
android:layout_centerHorizontal="true"
app:layout_anchorGravity="bottom"
android:layout_centerInParent="true" />
最佳答案
你的 CoordinatorLayout
是一个 FrameLayout
,所以试试这个方法,
希望对您有所帮助。
app:layout_anchorGravity="bottom|center"
关于android - 如何将 float 操作按钮对齐到中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32117341/