Android 浮动操作按钮周围的额外填充

Android 浮动操作按钮周围的额外填充,android,android-layout,floating-action-button,Android,Android Layout,Floating Action Button,我正在尝试用Android制作个人资料页面。我正在使用浮动操作按钮来显示用户图片 最初我想显示一张默认图片 我的xml代码如下所示: <android.support.design.widget.FloatingActionButton android:layout_height="100dp" android:layout_width="100dp" android:id="@+id/userIcon" app:fabSize="normal" a

我正在尝试用Android制作个人资料页面。我正在使用浮动操作按钮来显示用户图片

最初我想显示一张默认图片

我的xml代码如下所示:

<android.support.design.widget.FloatingActionButton
    android:layout_height="100dp"
    android:layout_width="100dp"
    android:id="@+id/userIcon"
    app:fabSize="normal"
    android:src="@drawable/male_icon"
    app:pressedTranslationZ="12dp"
    app:layout_anchor="@id/app_bar"
    app:layout_anchorGravity="bottom|center" />
Button fab = (Button) rootView.findViewById(R.id.fabbutton);

    Outline mOutlineCircle;
    int shapeSize = getResources().getDimensionPixelSize(R.dimen.shape_size);
    mOutlineCircle = new Outline();
    mOutlineCircle.setRoundRect(0, 0, shapeSize, shapeSize, shapeSize / 2);

    fab.setOutline(mOutlineCircle);
    fab.setClipToOutline(true);

我的问题是为什么晶圆厂周围有一些额外的空间。我不能去掉那个空间/填充物吗

编辑:

以下是我的完整xml代码:


试试这个:

app:borderWidth="0dp"
还可以使用“高程”删除阴影

app:elevation="6dp"
看到这个了吗

如果不起作用,则尝试如下方式管理轮廓阴影:

<android.support.design.widget.FloatingActionButton
    android:layout_height="100dp"
    android:layout_width="100dp"
    android:id="@+id/userIcon"
    app:fabSize="normal"
    android:src="@drawable/male_icon"
    app:pressedTranslationZ="12dp"
    app:layout_anchor="@id/app_bar"
    app:layout_anchorGravity="bottom|center" />
Button fab = (Button) rootView.findViewById(R.id.fabbutton);

    Outline mOutlineCircle;
    int shapeSize = getResources().getDimensionPixelSize(R.dimen.shape_size);
    mOutlineCircle = new Outline();
    mOutlineCircle.setRoundRect(0, 0, shapeSize, shapeSize, shapeSize / 2);

    fab.setOutline(mOutlineCircle);
    fab.setClipToOutline(true);

我想这是空白,不是空白。尝试以编程方式执行此操作:

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) floatingActionButton.getLayoutParams();
        params.setMargins(0, 0, 0, 0); 
        floatingActionButton.setLayoutParams(params);
    }
if(Build.VERSION.SDK\u INT
或者尝试将FloatingActionButton放入CoordinatorLayout,如下面的示例所示:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/bt_ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_marginRight="10dp"
        app:backgroundTint="@color/primary"
        app:borderWidth="0dp"
        app:fabSize="mini"/>
</android.support.design.widget.CoordinatorLayout>

u可能需要将scaletype属性更改为center。像

android:scaleType="center"

在布局文件中,将属性高程设置为0。因为它采用默认高程

 app:elevation="0dp"
现在在活动中检查api级别是否大于21,并根据需要设置标高

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        fabBtn.setElevation(10.0f);
    }

因为您使用的是相反的
应用程序:fabSize=“normal”
。更改为
app:fabSize=“mini”

您可以通过允许图标变大来删除额外的填充。通过这种方式,您可以将图标设置为浮动操作按钮的大小

    app:maxImageSize="40dp"

或者你想给它的任何大小。

你可以给边距像:android:layout\u margined=“7dp”android:layout\u marginBottom=“10dp”嘿@sagar,谢谢你的回复,但那没有帮助!我也在安卓5.1.1上进行了测试。同样的结果:|并确保您使用的是最新版本的design dependencyHey@Huy,尝试务实地解决它,但没有帮助。而且晶圆厂位于一个坐标布局内,请发布您的全部xml,dimens值:)您是否尝试使用了
android:scaleType=“center”
?设置布局宽度和高度以包装内容,并添加fabsize属性。谢谢,这非常适合我的要求。另外,最好提及
app:fabCustomSize=“您的自定义晶圆尺寸”
属性。