我在 FloatingActionButton 周围遇到了额外的边距或间距,但仅限于 API19。
API19 截图:
边距在所有其他版本上都是正确的,请参见下面的屏幕截图:
显示布局边界的开发者选项在这两种情况下都已打开。您可以清楚地看到,在 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/