[英]can't put the floating action button in the middle of two layouts
My XML file is : 我的XML文件是:
<?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. 在我的输出中,按钮在第一个linearLayout下方,而不是在它们之间。 How do I bring it in the center ?
如何将它带到中心?
You could use AppBarLayout
too instead of these LinearLayouts
btw: 您也可以使用
AppBarLayout
代替这些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" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.