【问题标题】:How to make FloatingButton stick to the bottom of WebView inside CoordinatorLayout?如何使浮动按钮粘在 CoordinatorLayout 内的 WebView 底部?
【发布时间】:2016-10-07 23:16:19
【问题描述】:

我需要使 FloatingActionButton 始终粘在显示 WebView 的片段底部。问题是我当前 XML 中的按钮被切成了两半,我无法修复它。这是我的布局。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorBackgroundWhite"
    tools:context=".fragments.CpuComparisionFragment">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <WebView
            android:id="@+id/web_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/button_compare"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end|bottom"
            android:layout_marginBottom="@dimen/fb_margin_16dp"
            android:layout_marginEnd="@dimen/fb_margin_16dp"
            android:alpha="0.7"
            android:src="@drawable/ic_compare" />

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

</FrameLayout>

我做错了什么?任何想法如何解决这一问题?这是我的应用程序现在的屏幕截图。

【问题讨论】:

    标签: android android-layout android-fragments android-coordinatorlayout floating-action-button


    【解决方案1】:

    您正在测试应用的设备上安装的 android 版本似乎不支持您的某些 xml 属性。无论如何,用下面的 sn-p 替换 FAB 代码。我希望它对你有用。

         <android.support.design.widget.FloatingActionButton
                    android:id="@+id/button_compare"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom|right"
                    android:layout_marginBottom="@dimen/fb_margin_16dp"
                    android:layout_marginEnd="@dimen/fb_margin_16dp"
                    android:alpha="0.7"
                    app:layout_anchorGravity="bottom|right|end"
                    android:src="@drawable/ic_compare" />
    

    【讨论】:

    • 你测试过这个吗?
    • 同样的情况。这不会改变任何事情。按钮仍然被切成两半。 ://
    • 转到清单并将您的应用主题更改为类似@style/AppTheme.NoActionBar
    【解决方案2】:

    尝试将 android:fitsSystemWindows="true" 添加到您的 FrameLayout 中。

    【讨论】:

    • 这没有帮助:(
    • 好的。尝试将 android:fitsSystemWindows="true" 添加到 Coordinator 布局以及 webView。
    • 您也可以提及您在哪个设备上测试它。
    • 我也将它添加到 CoordinatorLayout 中,但这并没有改变任何东西。我正在 ARM x86 API 23 上的 Nexus 5X 模拟器上对其进行测试。
    • 你能确认一下是不是只有按钮被按下而不是整个片段?
    猜你喜欢
    • 1970-01-01
    • 2021-04-08
    • 2018-02-14
    • 2018-12-01
    • 2021-02-09
    • 2020-07-19
    • 2015-11-15
    • 1970-01-01
    • 2015-08-26
    相关资源
    最近更新 更多