FloatingActionButton 周围的额外边距(间距)仅在 API 19
Extra margin(spacing) around FloatingActionButton only on API 19
我在 FloatingActionButton 周围遇到 e 额外的边距或间距,但仅在 API19.
API19 上的屏幕截图:
边距在所有其他版本上都是 正确的, 请参阅下面的屏幕截图:
显示布局边界的开发者选项在这两种情况下都打开了。你可以清楚地看到在 API 19 中有一个额外的 space在 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 没有帮助。间距仍然存在。
如果您希望所有 android 版本都使用相同的填充,请为 fab 设置 app:useCompatPadding="true"
这是因为 FAB 在 Lollipop 之前的设备上实现了特殊的填充。
您可以使用
app:useCompatPadding="true"
覆盖此行为。
boolean: true if FloatingActionButton is adding inner padding on
platforms Lollipop and after, to ensure consistent dimensions on all
platforms.
您可以programmatically
从floatingActionButton
[中删除margin
like.It 是一个已知问题,这是因为额外的保证金。
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"/>
我在 FloatingActionButton 周围遇到 e 额外的边距或间距,但仅在 API19.
API19 上的屏幕截图:
边距在所有其他版本上都是 正确的, 请参阅下面的屏幕截图:
显示布局边界的开发者选项在这两种情况下都打开了。你可以清楚地看到在 API 19 中有一个额外的 space在 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 没有帮助。间距仍然存在。
如果您希望所有 android 版本都使用相同的填充,请为 fab 设置 app:useCompatPadding="true"
这是因为 FAB 在 Lollipop 之前的设备上实现了特殊的填充。
您可以使用
app:useCompatPadding="true"
覆盖此行为。
boolean: true if FloatingActionButton is adding inner padding on platforms Lollipop and after, to ensure consistent dimensions on all platforms.
您可以programmatically
从floatingActionButton
[中删除margin
like.It 是一个已知问题,这是因为额外的保证金。
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"/>