Android 工具栏与浮动操作按钮重叠
我的布局是一项主要活动,在其中我用片段替换内容。我试图添加一个Android 工具栏与浮动操作按钮重叠,android,toolbar,Android,Toolbar,我的布局是一项主要活动,在其中我用片段替换内容。我试图添加一个FloatingActionButton,我希望按钮的一半在工具栏中,另一半在片段内容中。我附上一张我想要的结果的照片 但我明白了 工具栏与晶圆厂的一半重叠。 我尝试使工具栏透明,但没有任何更改 片段的代码是 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android
FloatingActionButton
,我希望按钮的一半在工具栏中,另一半在片段内容中。我附上一张我想要的结果的照片
但我明白了
工具栏与晶圆厂的一半重叠。
我尝试使工具栏透明,但没有任何更改
片段的代码是
<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"
android:fitsSystemWindows="true">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/home_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- contains archived and liked buttons -->
<LinearLayout
android:id="@+id/home_buttons"
android:layout_width="match_parent"
android:layout_height="40dp"
android:baselineAligned="false"
android:orientation="horizontal">
<!-- archived button -->
<FrameLayout
android:id="@+id/home_archived_button"
android:layout_width="0.0dp"
android:layout_height="match_parent"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="@color/orange">
<!-- archived button icon -->
<ImageView
android:id="@+id/home_archived_button_icon"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center_vertical|start"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:background="@mipmap/down_white_cyrcle_arrow"
android:contentDescription="@string/app_name" />
<!-- archived button -->
<TextView
android:id="@+id/home_archived_button_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="40dp"
android:layout_marginStart="40dp"
android:text="@string/home_archived"
android:textColor="@color/white" />
</FrameLayout>
<!--liked button -->
<FrameLayout
android:id="@+id/home_liked_button"
android:layout_width="0.0dp"
android:layout_height="match_parent"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:background="@color/orange">
<!-- liked button icon -->
<ImageView
android:id="@+id/home_liked_button_icon"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center_vertical|end"
android:layout_marginEnd="3dp"
android:layout_marginRight="3dp"
android:background="@mipmap/down_white_cyrcle_arrow"
android:contentDescription="@string/app_name" />
<!-- liked button text-->
<TextView
android:id="@+id/home_liked_button_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:layout_marginEnd="40dp"
android:layout_marginRight="40dp"
android:text="@string/home_liked"
android:textColor="@color/white" />
</FrameLayout>
</LinearLayout>
<!-- no matches -->
<RelativeLayout
android:id="@+id/home_no_matches_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<!-- no matches text -->
<TextView
android:id="@+id/home_no_matches"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="@string/home_no_matches"
android:textColor="@color/black"
android:visibility="gone" />
<!-- home invite button -->
<Button
android:id="@+id/home_invite_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/home_no_matches"
android:layout_centerHorizontal="true"
android:background="@color/orange"
android:padding="10dp"
android:text="@string/invite_friends"
android:textAllCaps="false"
android:textColor="@color/white"
android:visibility="gone" />
</RelativeLayout>
<!-- recyclerView for home fragment -->
<android.support.v7.widget.RecyclerView
android:id="@+id/home_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/home_buttons"
android:layout_marginBottom="35dp" />
<!-- search button -->
<FrameLayout
android:id="@+id/home_search_button"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_alignParentBottom="true"
android:background="@color/orange">
</FrameLayout>
</RelativeLayout>
<!--home add property -->
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
style="@style/floating_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="@mipmap/home_add_property"
app:backgroundTint="@color/white"
app:borderWidth="0dp"
app:elevation="0dp"
app:layout_anchor="@id/home_buttons"
app:layout_anchorGravity="top|center_horizontal" />
<!-- home search button -->
<android.support.design.widget.FloatingActionButton
android:id="@+id/home_search_fab"
style="@style/floating_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:src="@mipmap/home_search"
app:backgroundTint="@color/orange"
app:borderWidth="0dp"
app:elevation="0dp"
app:layout_anchor="@id/home_search_button"
app:layout_anchorGravity="bottom|center_horizontal" />
</android.support.design.widget.CoordinatorLayout>
活动的代码是
<?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:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:gravity="center"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:titleTextColor="@color/black">
<!-- toolbar title -->
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
还有晶圆厂的风格
<style name="floating_action_button">
<item name="android:layout_marginLeft">0dp</item>
<item name="android:layout_marginTop">-500dp</item>
<item name="android:layout_marginRight">0dp</item>
<item name="android:layout_marginBottom">-15dp</item>
</style>
0dp
-500dp
0dp
-15dp
好吧,用你的方式做这件事是不可能的。您的FAB位于片段
中,而工具栏
位于活动
中。我建议你做两件事中的一件:
1) 将FAB代码移动到活动
,并动态附加到it操作(如果需要与Fragment通信)
2) 将工具栏
移动到片段
。
无论如何,您可以使用如下锚定标记(它是xml中的一个FAB属性),而不是尝试在style.xml
中对齐您的FAB:
我是这样做的:
片段布局:
//实际内容
活动布局:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
它正在以视差模式崩溃。您可能希望更改它,以便始终看到您的按钮,但这是连接晶圆厂的正确方式。请发布相关代码,不清楚您如何连接晶圆厂。我已经尝试将晶圆厂代码移动到“活动”中。在本例中,片段与工具栏重叠,因此我只看到fab按钮的半顶部。我也使用app:layout_anchorGravity属性。不要使用晶圆厂的样式。请参见我的编辑示例该示例包含错误。On nestedScrollView属性显示有多个根标记。因为我已删除了它的内容。任何滚动视图都应该只有一个直接子视图是!在nestedScrollView中,我放置了一个RelayLevel布局,里面有所有的内容。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>