我正在尝试将底部导航栏与 FAB 重叠。我希望我的导航栏看起来像这样:
但它却像这样切断了按钮:
如何防止FAB被切断?这是我的 XML:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mobgen.designsprintapp.ui.main.MainActivity">
<LinearLayout 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:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="?android:attr/windowBackground"
android:backgroundTint="@color/colorPrimary"
app:itemBackground="@color/colorPrimary"
app:itemIconTint="@color/nav_item_color_state"
app:itemTextColor="@android:color/black"
app:menu="@menu/navigation" >
<android.support.design.widget.FloatingActionButton
android:id="@+id/tools"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
android:elevation="6dp"
android:scaleType="center"
app:srcCompat="@drawable/play" />
</android.support.design.widget.BottomNavigationView>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
你的问题是你已经明确指定了宽度和高度参数FloatingActionButton
,而它不能采用任何宽度/高度。app:fabSize https://developer.android.com/reference/android/support/design/widget/FloatingActionButton.html#attr_android.support.design:fabSize参数指定 fab 的 3 种尺寸:自动、迷你和正常。
Leave layout_width
and layout_height
as wrap_content
,并使用指定所需的晶圆厂尺寸app:fabSize="normal"
(或列表中的其他参数)。
另外,使BottomNavigationView
的身高wrap_content
,因为 fab 有一些内部填充。
为了在封闭布局之外绘制子级,请应用android:clipChildren="false" https://developer.android.com/reference/android/view/ViewGroup.html#attr_android:clipChildren到封闭的ViewGroup
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)