代码之家  ›  专栏  ›  技术社区  ›  Adam Varhegyi

仅在API 19上浮动操作按钮周围的额外边距(间距)

  •  3
  • Adam Varhegyi  · 技术社区  · 7 年前

    我在floatingactionbutton周围遇到e xtra边距或间距。 but only on api19.

    API19屏幕截图:

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

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

    xml:

    <relativelayout
    android:layout_width=“包装内容”
    android:layout_height=“包装内容”
    android:orientation=“垂直”>
    
    <android.support.design.widget.floatingActionButton
    android:id=“@+id/路径\u btn”
    android:layout_width=“包装内容”
    android:layout_height=“包装内容”
    android:layout_marginlet=“12dp”
    android:layout_marginright=“12dp”
    android:layout_margintop=“12dp”
    android:background=“@null”
    app:backgroundtint=“@颜色/蓝色\浅”
    app:srccompt=“@drawable/ic_line”/>
    
    <android.support.design.widget.floatingActionButton
    android:id=“@+id/流\切换\u btn”
    android:layout_width=“包装内容”
    android:layout_height=“包装内容”
    android:layout_below=“@+id/path_btn”
    android:layout_marginbottom=“12dp”
    android:layout_marginlet=“12dp”
    android:layout_margintop=“12dp”
    android:background=“@null”
    app:srccompt=“@drawable/ic_stream_video_white”/>gt;
    </relativelayout>
    

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

    如果可以的话,请提供帮助。

    谢谢。

    e d i t:

    正在添加

    app:usecompatpadding=“true”
    

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

    enter image description here

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

    enter image description here

    的开发人员选项在这两种情况下都启用了显示布局边界。您可以清楚地看到,在API 19中,晶圆厂周围有一个额外的空间。

    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中的边距只添加紫色区域在屏幕截图上。如果我去掉空白,多余的间距就不会消失。

    如果可以,请帮忙。

    谢谢。

    E D I T:

    添加

      app:useCompatPadding="true"
    

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

    3 回复  |  直到 7 年前
        1
  •  4
  •   Jay Rathod Frank Singhal    7 年前

    programmatically margin floatingActionButton

    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"/>
    
        2
  •  2
  •   Anton A.    7 年前

    app:useCompatPadding="true"
    

        3
  •  0
  •   user8959091    7 年前

    app:useCompatPadding="true"