android - 仅在 API 19 上围绕 FloatingActionButton 的额外边距(间距)

标签 android android-layout floating-action-button

我在 FloatingActionButton 周围遇到了额外的边距或间距,但仅限于 API19。

API19 截图:

enter image description here

边距在所有其他版本上都是正确的,请参见下面的屏幕截图:

enter image description here

显示布局边界的开发者选项在这两种情况下都已打开。您可以清楚地看到,在 API 19 中,FAB 周围有一个额外的空间。

XML:

      <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="vertical">

                        <android.support.design.widget.FloatingActionButton
                            android:id="@+id/path_btn"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="12dp"
                            android:layout_marginRight="12dp"
                            android:layout_marginTop="12dp"
                            android:background="@null"
                            app:backgroundTint="@color/blue_light"
                            app:srcCompat="@drawable/ic_line" />

                        <android.support.design.widget.FloatingActionButton
                            android:id="@+id/stream_toggle_btn"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/path_btn"
                            android:layout_marginBottom="12dp"
                            android:layout_marginLeft="12dp"
                            android:layout_marginTop="12dp"
                            android:background="@null"
                            app:srcCompat="@drawable/ic_stream_video_white" />
                    </RelativeLayout>

请注意 XML 中的边距只会在屏幕截图上添加紫色区域。如果我删除边距,额外的间距不会消失。

如果可以,请帮忙。

谢谢。

编辑:

添加

  app:useCompatPadding="true"

对 FABS 没有帮助。间距仍然存在。

最佳答案

您可以以编程方式floatingActionButton中移除margin em> like.It is a known issue and it is because of extra margin.

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) stream_toggle_btn.getLayoutParams();
    params.setMargins(0, 0, 0, 0); 
    stream_toggle_btn.setLayoutParams(params);

    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) path_btn.getLayoutParams();
    params.setMargins(0, 0, 0, 0); 
    path_btn.setLayoutParams(params);
}

编辑

尝试在 FloatingActionButton xml 中使用此属性。

app:elevation="0dp"
app:pressedTranslationZ="0dp"

喜欢

<android.support.design.widget.FloatingActionButton
    android:id="@+id/path_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="12dp"
    android:layout_marginRight="12dp"
    android:layout_marginTop="12dp"
    android:background="@null"
    app:backgroundTint="@color/blue_light"
    app:srcCompat="@drawable/ic_line"
    app:elevation="0dp"
    app:pressedTranslationZ="0dp"/>

关于android - 仅在 API 19 上围绕 FloatingActionButton 的额外边距(间距),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51243882/

相关文章:

Android:将responseBody中的一个String分成2个String值

android - ScrollView 布局没有填满整个屏幕

android - 如何在约束布局中为 ImageView 设置完美的纵横比

android - 在 dimensions.xml 中使用 FILL_PARENT

android - 在不重新填充的情况下更新 GridView/ListView

Android 应用程序在启动时无缘无故地崩溃

android - Marshmallow 更新设备中的运行时权限弹出单击问题

android - Xamarin.Forms 中的 float 操作按钮

android - 如何使用fab风格的钻石?

android - 在模拟器上找不到 float 操作按钮