仅在API 19上的FloatingActionButton周围有多余的边距 [英] Extra margin(spacing) around FloatingActionButton only on API 19

查看:145
本文介绍了仅在API 19上的FloatingActionButton周围有多余的边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在FloatingActionButton上遇到e xtra边距或间距,但仅在API19上.

I'm experiencing an extra margin or spacing around FloatingActionButton but only on API19.

API19上的屏幕截图:

每个其他版本上的保证金都是正确的,请参见下面的屏幕截图:

Margin is correct on every other version, see screenshot below:

在两种情况下都会打开用于显示布局边界的开发人员选项.您可以清楚地看到,在API 19中,FAB周围有多余的空间.

The developer option for showing layout boundaries is turned on in both cases. You can clearly see that in API 19 there is an extra space around the FABs.

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中的边距仅在屏幕截图上添加了紫色区域.如果我删除页边距,多余的间距不会消失.

Please consider that the margins in the XML only adds the purple area on the screenshots. If I remove the margins the extra spacing does not disappear.

请帮助.

谢谢.

E D I T:

添加

  app:useCompatPadding="true"

致FABS没有帮助.间距仍然存在.

To FABS does not help. Spacing still there.

推荐答案

您可以 programmatically floatingActionButton 中删除 margin > like.这是一个已知问题,这是因为有额外的利润.

You can programmatically remove margin from floatingActionButton 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中使用此属性.

Try to use this properties inside 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"/>

这篇关于仅在API 19上的FloatingActionButton周围有多余的边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆