【发布时间】:2016-04-14 13:03:51
【问题描述】:
我需要在 android 中锚定浮动操作按钮,但遇到了麻烦: 晶圆厂将在导航视图中 这是我的 activity_main 布局。 它包括导航抽屉。
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackground">
<!-- The main content view -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
layout="@layout/toolbar_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<!-- The navigation drawer -->
<include
layout="@layout/nav_drawer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"/>
</android.support.v4.widget.DrawerLayout>
导航抽屉布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/clDrawer"
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:background="@color/colorPrimary">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.NavigationView
android:id="@+id/navView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/menu_drawer_view"
app:headerLayout="@layout/anav_header"
android:background="@color/colorPrimary2"
app:itemIconTint="@color/colorIcon"
app:itemTextColor="@color/colorIcon"/>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/navFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/activity_horizontal_margin"
android:clickable="true"
android:src="@drawable/plus_icon"
app:backgroundTint="@color/colorIcon"
app:layout_anchor="@id/headerLayout"
app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>
我的导航视图anav_header 只包含少数文本视图。
我需要将 fab 锚定到标题的底部,就在标题和 ND 的主要内容之间。
问题是 layout_anchor 仅在标题和导航视图位于相同布局中时才有效。如果我使用 navigationview 属性 headerLayout , layout_anchor 不起作用。另外,如果我使用NavigationView.addHeaderView(),它也不起作用。
如果我通过这种方式在导航视图布局中包含标题
<include
layout="@layout/anav_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
它可以工作,但是标题和导航视图像不同的部分一样移动。我需要他们像一个导航抽屉一样行事。 I need navigation drawer to lookes smth like that.
【问题讨论】:
-
只需将 FloatingActionButton 代码放在标题布局 xml 中,而不是放在主要内容中
-
@Pavan,是的,但是 fab 将始终位于标题的底部,并且永远不会位于标题和主要内容布局之间。
-
@TooLazy 你有没有找到将FAB 放在
NavigationView中的标题和菜单之间的方法?
标签: java android material-design