android - 无法将我的 fab 图标设置到我页面的右下角

标签 android floating-action-button

即使我将 anchor 设置为 bottom|right,我也无法在应用程序的右下角插入 fab 图标应用程序的左上部分。

    <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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.kun.carkila.OwnerTabs">

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="top|left"
    android:layout_margin="@dimen/fab_margin"
    app:srcCompat="@drawable/plus"
    app:layout_anchor="@+id/container"
    app:layout_anchorGravity="bottom|right" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="top|left"
    android:layout_margin="@dimen/fab_margin"
    app:srcCompat="@drawable/ic_directions_car_white_48dp"
    app:layout_anchor="@+id/container"
    app:layout_anchorGravity="bottom|right" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:minHeight="?attr/actionBarSize"
        android:background="#990000"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/appbar_padding_top"
    android:theme="@style/AppTheme.AppBarOverlay"
    android:background="#990000">

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

</android.support.design.widget.AppBarLayout>



<android.support.v4.view.ViewPager
    android:id="@+id/container"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />


</LinearLayout>

最佳答案

首先,要使用 anchor 属性,您应该将 CoordinatorLayout 作为父 View 。 其次,您的 float 按钮 View 位于 AppBarLayout 中,它始终位于屏幕顶部。

将 float 按钮从AppBarLayout中取出,并使用CoordinatorLayout作为父 View 。

关于android - 无法将我的 fab 图标设置到我页面的右下角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40918660/

相关文章:

android - Fab in Coordinator layout with bottom padding

android - 如何让一个屏幕包含google MapView和ListView?

android - 如何设置 TextView 颜色与角度的渐变?

Android Studio 构建错误无法解析所有依赖项

android - FloatingActionButton 未在 API 16 上显示

android - InflateException 因为 Android 5.0 + 上的 float 操作按钮上的样式属性

android - 使用 BottomAppBar Material 设计组件的 fragment 过渡

android - 动画期间 ImageView 上的 OnTouchListener,有时不会触发/调用

java - android - 在带有滚动的可扩展 ListView 中加载json

android - BottomNavigationView 与项目背景覆盖 FAB